@Override
    public List<TriggerFiredResult> triggersFired(List<OperableTrigger> triggers, Jedis jedis) throws JobPersistenceException, ClassNotFoundException {
        List<TriggerFiredResult> results = new ArrayList<>();
        for (OperableTrigger trigger : triggers) {
            final String triggerHashKey = redisSchema.triggerHashKey(trigger.getKey());
            logger.debug(String.format("Trigger %s fired.", triggerHashKey));
            Pipeline pipe = jedis.pipelined();
            Response<Boolean> triggerExistsResponse = pipe.exists(triggerHashKey);
            Response<Double> triggerAcquiredResponse = pipe.zscore(redisSchema.triggerStateKey(RedisTriggerState.ACQUIRED), triggerHashKey);
            pipe.sync();
            if(!triggerExistsResponse.get() || triggerAcquiredResponse.get() == null){
                // the trigger does not exist or the trigger is not acquired
                if(!triggerExistsResponse.get()){
                    logger.debug(String.format("Trigger %s does not exist.", triggerHashKey));
                }
                else{
                    logger.debug(String.format("Trigger %s was not acquired.", triggerHashKey));
                }
                continue;
            }
            Calendar calendar = null;
            final String calendarName = trigger.getCalendarName();
            if(calendarName != null){
                calendar = retrieveCalendar(calendarName, jedis);
                if(calendar == null){
                    continue;
                }
            }

            final Date previousFireTime = trigger.getPreviousFireTime();
            trigger.triggered(calendar);

            // set the trigger state to WAITING
            final Date nextFireDate = trigger.getNextFireTime();
            long nextFireTime = 0;
            if (nextFireDate != null) {
                nextFireTime = nextFireDate.getTime();
                jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, Long.toString(nextFireTime));
                setTriggerState(RedisTriggerState.WAITING, (double) nextFireTime, triggerHashKey, jedis);
            }

            JobDetail job = retrieveJob(trigger.getJobKey(), jedis);
            TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(job, trigger, calendar, false, new Date(), previousFireTime, previousFireTime, nextFireDate);

            // handling jobs for which concurrent execution is disallowed
            if (isJobConcurrentExecutionDisallowed(job.getJobClass())){
                if (logger.isTraceEnabled()) {
                    logger.trace("Firing trigger " + trigger.getKey() + " for job " + job.getKey() + " for which concurrent execution is disallowed. Adding job to blocked jobs set.");
                }
                final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
                final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(job.getKey());
                for (String nonConcurrentTriggerHashKey : jedis.smembers(jobTriggerSetKey)) {
                    Double score = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.WAITING), nonConcurrentTriggerHashKey);
                    if(score != null){
                        if (logger.isTraceEnabled()) {
                            logger.trace("Setting state of trigger " + trigger.getKey() + " for non-concurrent job " + job.getKey() + " to BLOCKED.");
                        }
                        setTriggerState(RedisTriggerState.BLOCKED, score, nonConcurrentTriggerHashKey, jedis);
                        // setting trigger state removes trigger locks, so re-lock
                        lockTrigger(redisSchema.triggerKey(nonConcurrentTriggerHashKey), jedis);
                    }
                    else{
                        score = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED), nonConcurrentTriggerHashKey);
                        if(score != null){
                            if (logger.isTraceEnabled()) {
                                logger.trace("Setting state of trigger " + trigger.getKey() + " for non-concurrent job " + job.getKey() + " to PAUSED_BLOCKED.");
                            }
                            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, score, nonConcurrentTriggerHashKey, jedis);
                            // setting trigger state removes trigger locks, so re-lock
                            lockTrigger(redisSchema.triggerKey(nonConcurrentTriggerHashKey), jedis);
                        }
                    }
                }
                pipe = jedis.pipelined();
                pipe.set(redisSchema.jobBlockedKey(job.getKey()), schedulerInstanceId);
                pipe.sadd(redisSchema.blockedJobsSet(), jobHashKey);
                pipe.sync();
            } else if(nextFireDate != null){
                jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, Long.toString(nextFireTime));
                logger.debug(String.format("Releasing trigger %s with next fire time %s. Setting state to WAITING.", triggerHashKey, nextFireTime));
                setTriggerState(RedisTriggerState.WAITING, (double) nextFireTime, triggerHashKey, jedis);
            } else {
                jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, "");
                unsetTriggerState(triggerHashKey, jedis);
            }
            jedis.hset(triggerHashKey, TRIGGER_PREVIOUS_FIRE_TIME, Long.toString(System.currentTimeMillis()));

            results.add(new TriggerFiredResult(triggerFiredBundle));
        }
        return results;
    }
@ Override public List < TriggerFiredResult > triggersFired ( List < OperableTrigger > triggers , Jedis jedis ) throws JobPersistenceException , ClassNotFoundException { List < TriggerFiredResult > results = new ArrayList < > ( ) ; for ( OperableTrigger trigger : triggers ) { final String triggerHashKey = redisSchema . triggerHashKey ( trigger . getKey ( ) ) ; logger . debug ( String . format ( "Trigger %s fired." , triggerHashKey ) ) ; Pipeline pipe = jedis . pipelined ( ) ; Response < Boolean > triggerExistsResponse = pipe . exists ( triggerHashKey ) ; Response < Double > triggerAcquiredResponse = pipe . zscore ( redisSchema . triggerStateKey ( RedisTriggerState . ACQUIRED ) , triggerHashKey ) ; pipe . sync ( ) ; if ( ! triggerExistsResponse . get ( ) || triggerAcquiredResponse . get ( ) == null ) { if ( ! triggerExistsResponse . get ( ) ) { logger . debug ( String . format ( "Trigger %s does not exist." , triggerHashKey ) ) ; } else { logger . debug ( String . format ( "Trigger %s was not acquired." , triggerHashKey ) ) ; } continue ; } Calendar calendar = null ; final String calendarName = trigger . getCalendarName ( ) ; if ( calendarName != null ) { calendar = retrieveCalendar ( calendarName , jedis ) ; if ( calendar == null ) { continue ; } } final Date previousFireTime = trigger . getPreviousFireTime ( ) ; trigger . triggered ( calendar ) ; final Date nextFireDate = trigger . getNextFireTime ( ) ; long nextFireTime = 0 ; if ( nextFireDate != null ) { nextFireTime = nextFireDate . getTime ( ) ; jedis . hset ( triggerHashKey , TRIGGER_NEXT_FIRE_TIME , Long . toString ( nextFireTime ) ) ; setTriggerState ( RedisTriggerState . WAITING , ( double ) nextFireTime , triggerHashKey , jedis ) ; } JobDetail job = retrieveJob ( trigger . getJobKey ( ) , jedis ) ; TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle ( job , trigger , calendar , false , new Date ( ) , previousFireTime , previousFireTime , nextFireDate ) ; if ( isJobConcurrentExecutionDisallowed ( job . getJobClass ( ) ) ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Firing trigger " + trigger . getKey ( ) + " for job " + job . getKey ( ) + " for which concurrent execution is disallowed. Adding job to blocked jobs set." ) ; } final String jobHashKey = redisSchema . jobHashKey ( trigger . getJobKey ( ) ) ; final String jobTriggerSetKey = redisSchema . jobTriggersSetKey ( job . getKey ( ) ) ; for ( String nonConcurrentTriggerHashKey : jedis . smembers ( jobTriggerSetKey ) ) { Double score = jedis . zscore ( redisSchema . triggerStateKey ( RedisTriggerState . WAITING ) , nonConcurrentTriggerHashKey ) ; if ( score != null ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Setting state of trigger " + trigger . getKey ( ) + " for non-concurrent job " + job . getKey ( ) + " to BLOCKED." ) ; } setTriggerState ( RedisTriggerState . BLOCKED , score , nonConcurrentTriggerHashKey , jedis ) ; lockTrigger ( redisSchema . triggerKey ( nonConcurrentTriggerHashKey ) , jedis ) ; } else { score = jedis . zscore ( redisSchema . triggerStateKey ( RedisTriggerState . PAUSED ) , nonConcurrentTriggerHashKey ) ; if ( score != null ) { if ( logger . isTraceEnabled ( ) ) { logger . trace ( "Setting state of trigger " + trigger . getKey ( ) + " for non-concurrent job " + job . getKey ( ) + " to PAUSED_BLOCKED." ) ; } setTriggerState ( RedisTriggerState . PAUSED_BLOCKED , score , nonConcurrentTriggerHashKey , jedis ) ; lockTrigger ( redisSchema . triggerKey ( nonConcurrentTriggerHashKey ) , jedis ) ; } } } pipe = jedis . pipelined ( ) ; pipe . set ( redisSchema . jobBlockedKey ( job . getKey ( ) ) , schedulerInstanceId ) ; pipe . sadd ( redisSchema . blockedJobsSet ( ) , jobHashKey ) ; pipe . sync ( ) ; } else if ( nextFireDate != null ) { jedis . hset ( triggerHashKey , TRIGGER_NEXT_FIRE_TIME , Long . toString ( nextFireTime ) ) ; logger . debug ( String . format ( "Releasing trigger %s with next fire time %s. Setting state to WAITING." , triggerHashKey , nextFireTime ) ) ; setTriggerState ( RedisTriggerState . WAITING , ( double ) nextFireTime , triggerHashKey , jedis ) ; } else { jedis . hset ( triggerHashKey , TRIGGER_NEXT_FIRE_TIME , "" ) ; unsetTriggerState ( triggerHashKey , jedis ) ; } jedis . hset ( triggerHashKey , TRIGGER_PREVIOUS_FIRE_TIME , Long . toString ( System . currentTimeMillis ( ) ) ) ; results . add ( new TriggerFiredResult ( triggerFiredBundle ) ) ; } return results ; }
Inform the <code>JobStore</code> that the scheduler is now firing the
given <code>Trigger</code> (executing its associated <code>Job</code>),
that it had previously acquired (reserved).
@param triggers a list of triggers
@param jedis a thread-safe Redis connection
@return may return null if all the triggers or their calendars no longer exist, or
if the trigger was not successfully put into the 'executing'
state.  Preference is to return an empty list if none of the triggers
could be fired.