Java Code Examples for org.quartz.spi.OperableTrigger#getJobDataMap()

The following examples show how to use org.quartz.spi.OperableTrigger#getJobDataMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Helper to warn when a limited trigger won't fire because its node is missing.
 */
private boolean isLimitedToMissingNode(final TriggerEntity entity) {
  OperableTrigger trigger = entity.getValue();
  JobDataMap triggerDetail = trigger.getJobDataMap();
  if (triggerDetail.containsKey(LIMIT_NODE_KEY)) {
    String limitedNodeId = triggerDetail.getString(LIMIT_NODE_KEY);
    // can skip members check here because "local()" has already filtered limited triggers down to those
    // which are either limited to run on the current node, or on a missing node (ie. have been orphaned)
    if (!nodeAccess.getId().equals(limitedNodeId)) {
      // not limited to this node, so must be an orphaned trigger
      String description = trigger.getDescription();
      if (Strings2.isBlank(description)) {
        description = trigger.getJobKey().getName();
      }
      if (Strings2.isBlank(limitedNodeId)) {
        log.warn("Cannot run task '{}' because it is not configured for HA", description);
      }
      else {
        log.warn("Cannot run task '{}' because it uses node {} which is not a member of this cluster", description,
            limitedNodeId);
      }
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: RedisClusterStorage.java    From quartz-redis-jobstore with Apache License 2.0 4 votes vote down vote up
/**
 * Store a trigger in redis
 *
 * @param trigger         the trigger to be stored
 * @param replaceExisting true if an existing trigger with the same identity should be replaced
 * @param jedis           a thread-safe Redis connection
 * @throws JobPersistenceException
 * @throws ObjectAlreadyExistsException
 */
@Override
public void storeTrigger(OperableTrigger trigger, boolean replaceExisting, JedisClusterCommandsWrapper jedis) throws JobPersistenceException {
    final String triggerHashKey = redisSchema.triggerHashKey(trigger.getKey());
    final String triggerGroupSetKey = redisSchema.triggerGroupSetKey(trigger.getKey());
    final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(trigger.getJobKey());

    if (!(trigger instanceof SimpleTrigger) && !(trigger instanceof CronTrigger)) {
        throw new UnsupportedOperationException("Only SimpleTrigger and CronTrigger are supported.");
    }
    final boolean exists = jedis.exists(triggerHashKey);
    if (exists && !replaceExisting) {
        throw new ObjectAlreadyExistsException(trigger);
    }

    Map<String, String> triggerMap = mapper.convertValue(trigger, new TypeReference<HashMap<String, String>>() {
    });
    triggerMap.put(TRIGGER_CLASS, trigger.getClass().getName());

    jedis.hmset(triggerHashKey, triggerMap);
    jedis.sadd(redisSchema.triggersSet(), triggerHashKey);
    jedis.sadd(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
    jedis.sadd(triggerGroupSetKey, triggerHashKey);
    jedis.sadd(jobTriggerSetKey, triggerHashKey);
    if (trigger.getCalendarName() != null && !trigger.getCalendarName().isEmpty()) {
        final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(trigger.getCalendarName());
        jedis.sadd(calendarTriggersSetKey, triggerHashKey);
    }
    if (trigger.getJobDataMap() != null && !trigger.getJobDataMap().isEmpty()) {
        final String triggerDataMapHashKey = redisSchema.triggerDataMapHashKey(trigger.getKey());
        jedis.hmset(triggerDataMapHashKey, getStringDataMap(trigger.getJobDataMap()));
    }

    if (exists) {
        // We're overwriting a previously stored instance of this trigger, so clear any existing trigger state.
        unsetTriggerState(triggerHashKey, jedis);
    }

    Boolean triggerPausedResponse = jedis.sismember(redisSchema.pausedTriggerGroupsSet(), triggerGroupSetKey);
    Boolean jobPausedResponse = jedis.sismember(redisSchema.pausedJobGroupsSet(), redisSchema.jobGroupSetKey(trigger.getJobKey()));

    if (triggerPausedResponse || jobPausedResponse) {
        final long nextFireTime = trigger.getNextFireTime() != null ? trigger.getNextFireTime().getTime() : -1;
        final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
        if (isBlockedJob(jobHashKey, jedis)) {
            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, (double) nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.PAUSED, (double) nextFireTime, triggerHashKey, jedis);
        }
    } else if (trigger.getNextFireTime() != null) {
        setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis);
    }
}
 
Example 3
Source File: RedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 4 votes vote down vote up
/**
 * Store a trigger in redis
 * @param trigger the trigger to be stored
 * @param replaceExisting true if an existing trigger with the same identity should be replaced
 * @param jedis a thread-safe Redis connection
 * @throws JobPersistenceException
 * @throws ObjectAlreadyExistsException
 */
@Override
public void storeTrigger(OperableTrigger trigger, boolean replaceExisting, Jedis jedis) throws JobPersistenceException {
    final String triggerHashKey = redisSchema.triggerHashKey(trigger.getKey());
    final String triggerGroupSetKey = redisSchema.triggerGroupSetKey(trigger.getKey());
    final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(trigger.getJobKey());

    if(!(trigger instanceof SimpleTrigger) && !(trigger instanceof CronTrigger)){
        throw new UnsupportedOperationException("Only SimpleTrigger and CronTrigger are supported.");
    }
    final boolean exists = jedis.exists(triggerHashKey);
    if(exists && !replaceExisting){
        throw new ObjectAlreadyExistsException(trigger);
    }

    Map<String, String> triggerMap = mapper.convertValue(trigger, new TypeReference<HashMap<String, String>>() {});
    triggerMap.put(TRIGGER_CLASS, trigger.getClass().getName());

    Pipeline pipe = jedis.pipelined();
    pipe.hmset(triggerHashKey, triggerMap);
    pipe.sadd(redisSchema.triggersSet(), triggerHashKey);
    pipe.sadd(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
    pipe.sadd(triggerGroupSetKey, triggerHashKey);
    pipe.sadd(jobTriggerSetKey, triggerHashKey);
    if(trigger.getCalendarName() != null && !trigger.getCalendarName().isEmpty()){
        final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(trigger.getCalendarName());
        pipe.sadd(calendarTriggersSetKey, triggerHashKey);
    }
    if (trigger.getJobDataMap() != null && !trigger.getJobDataMap().isEmpty()) {
        final String triggerDataMapHashKey = redisSchema.triggerDataMapHashKey(trigger.getKey());
        pipe.hmset(triggerDataMapHashKey, getStringDataMap(trigger.getJobDataMap()));
    }
    pipe.sync();

    if(exists){
        // We're overwriting a previously stored instance of this trigger, so clear any existing trigger state.
        unsetTriggerState(triggerHashKey, jedis);
    }

    pipe = jedis.pipelined();
    Response<Boolean> triggerPausedResponse = pipe.sismember(redisSchema.pausedTriggerGroupsSet(), triggerGroupSetKey);
    Response<Boolean> jobPausedResponse = pipe.sismember(redisSchema.pausedJobGroupsSet(), redisSchema.jobGroupSetKey(trigger.getJobKey()));
    pipe.sync();
    final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
    final long nextFireTime = trigger.getNextFireTime() != null ? trigger.getNextFireTime().getTime() : -1;
    if (triggerPausedResponse.get() || jobPausedResponse.get()){
        if (isBlockedJob(jobHashKey, jedis)) {
            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, (double) nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.PAUSED, (double) nextFireTime, triggerHashKey, jedis);
        }
    } else if(trigger.getNextFireTime() != null){
        if (isBlockedJob(jobHashKey, jedis)) {
            setTriggerState(RedisTriggerState.BLOCKED, nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis);
        }
    }
}