org.quartz.spi.OperableTrigger Java Examples

The following examples show how to use org.quartz.spi.OperableTrigger. 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: SimpleTriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public int insertExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {

        SimpleTrigger simpleTrigger = (SimpleTrigger)trigger;
        
        PreparedStatement ps = null;
        
        try {
            ps = conn.prepareStatement(Util.rtp(INSERT_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral));
            ps.setString(1, trigger.getKey().getName());
            ps.setString(2, trigger.getKey().getGroup());
            ps.setInt(3, simpleTrigger.getRepeatCount());
            ps.setBigDecimal(4, new BigDecimal(String.valueOf(simpleTrigger.getRepeatInterval())));
            ps.setInt(5, simpleTrigger.getTimesTriggered());

            return ps.executeUpdate();
        } finally {
            Util.closeStatement(ps);
        }
    }
 
Example #2
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void doUpdateOfMisfiredTrigger(Connection conn, OperableTrigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
    Calendar cal = null;
    if (trig.getCalendarName() != null) {
        cal = retrieveCalendar(conn, trig.getCalendarName());
    }

    schedSignaler.notifyTriggerListenersMisfired(trig);

    trig.updateAfterMisfire(cal);

    if (trig.getNextFireTime() == null) {
        storeTrigger(conn, trig,
            null, true, STATE_COMPLETE, forceState, recovering);
        schedSignaler.notifySchedulerListenersFinalized(trig);
    } else {
        storeTrigger(conn, trig, null, true, newStateIfNotComplete,
                forceState, false);
    }
}
 
Example #3
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected boolean updateMisfiredTrigger(Connection conn,
        TriggerKey triggerKey, String newStateIfNotComplete, boolean forceState)
    throws JobPersistenceException {
    try {

        OperableTrigger trig = retrieveTrigger(conn, triggerKey);

        long misfireTime = System.currentTimeMillis();
        if (getMisfireThreshold() > 0) {
            misfireTime -= getMisfireThreshold();
        }

        if (trig.getNextFireTime().getTime() > misfireTime) {
            return false;
        }

        doUpdateOfMisfiredTrigger(conn, trig, forceState, newStateIfNotComplete, false);

        return true;

    } catch (Exception e) {
        throw new JobPersistenceException(
                "Couldn't update misfired trigger '" + triggerKey + "': " + e.getMessage(), e);
    }
}
 
Example #4
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 #5
Source File: CronTriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public int insertExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {

        CronTrigger cronTrigger = (CronTrigger)trigger;
        
        PreparedStatement ps = null;
        
        try {
            ps = conn.prepareStatement(Util.rtp(INSERT_CRON_TRIGGER, tablePrefix, schedNameLiteral));
            ps.setString(1, trigger.getKey().getName());
            ps.setString(2, trigger.getKey().getGroup());
            ps.setString(3, cronTrigger.getCronExpression());
            ps.setString(4, cronTrigger.getTimeZone().getID());

            return ps.executeUpdate();
        } finally {
            Util.closeStatement(ps);
        }
    }
 
Example #6
Source File: AbstractQuartzTaskManager.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected synchronized void resumeLocalTask(String taskName) throws TaskException {
    String taskGroup = this.getTenantTaskGroup();
    if (!this.containsLocalTask(taskName, taskGroup)) {
        throw new TaskException("Non-existing task for resuming with name: " + taskName,
                Code.NO_TASK_EXISTS);
    }
    try {
        Trigger trigger = this.getScheduler().getTrigger(new TriggerKey(taskName, taskGroup));
        if (trigger instanceof OperableTrigger) {
            ((OperableTrigger) trigger).setNextFireTime(
                    ((OperableTrigger) trigger).getFireTimeAfter(null));
        }
        this.getScheduler().resumeJob(new JobKey(taskName, taskGroup));
    } catch (SchedulerException e) {
        throw new TaskException("Error in resuming task with name: " + taskName,
                Code.UNKNOWN, e);
    }
}
 
Example #7
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void storeJobsAndTriggers(final Map<JobDetail, Set<? extends Trigger>> jobsAndTriggers,
                                 final boolean replace)
    throws JobPersistenceException
{
  executeWrite(db -> {
    for (Entry<JobDetail, Set<? extends Trigger>> entry : jobsAndTriggers.entrySet()) {
      JobDetail jobDetail = entry.getKey();
      storeJob(db, jobDetail, replace);

      Set<? extends Trigger> triggers = entry.getValue();
      for (Trigger trigger : triggers) {
        storeTrigger(db, (OperableTrigger) trigger, replace);
      }
    }
    return null;
  });
}
 
Example #8
Source File: TriggerSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static CompositeData toCompositeData(Trigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getKey().getName(),
                        trigger.getKey().getGroup(),
                        trigger.getJobKey().getName(),
                        trigger.getJobKey().getGroup(),
                        trigger.getDescription(),
                        JobDataMapSupport.toTabularData(trigger
                                .getJobDataMap()),
                        trigger.getCalendarName(),
                        ((OperableTrigger)trigger).getFireInstanceId(),
                        trigger.getMisfireInstruction(),
                        trigger.getPriority(), trigger.getStartTime(),
                        trigger.getEndTime(), trigger.getNextFireTime(),
                        trigger.getPreviousFireTime(),
                        trigger.getFinalFireTime() });
    } catch (OpenDataException e) {
        throw new RuntimeException(e);
    }
}
 
Example #9
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Resume (un-pause) all of the <code>{@link org.quartz.JobDetail}s</code> in the given group.
 * </p>
 * <p>
 * If any of the <code>Job</code> s had <code>Trigger</code> s that missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 */
@Override
public Collection<String> resumeJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException {
  Collection<String> groups = new HashSet<String>();
  lock();
  try {
    Set<JobKey> jobKeys = getJobKeys(matcher);

    for (JobKey jobKey : jobKeys) {
      if (groups.add(jobKey.getGroup())) {
        jobFacade.removePausedJobGroup(jobKey.getGroup());
      }
      for (OperableTrigger trigger : getTriggersForJob(jobKey)) {
        resumeTrigger(trigger.getKey());
      }
    }
  } finally {
    unlock();
  }
  return groups;
}
 
Example #10
Source File: AbstractQuartzTaskManager.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
protected synchronized void resumeLocalTask(String taskName) throws TaskException {
    String taskGroup = this.getTenantTaskGroup();
    if (!this.isPreviouslyScheduled(taskName, taskGroup)) {
        throw new TaskException("Non-existing task for resuming with name: " + taskName,
                                TaskException.Code.NO_TASK_EXISTS);
    }
    try {
        Trigger trigger = this.getScheduler().getTrigger(new TriggerKey(taskName, taskGroup));
        if (trigger instanceof OperableTrigger) {
            ((OperableTrigger) trigger).setNextFireTime(trigger.getFireTimeAfter(null));
        }
        this.getScheduler().resumeJob(new JobKey(taskName, taskGroup));
        log.info("Task resumed: [" + this.getTaskType() + "][" + taskName + "]");
    } catch (SchedulerException e) {
        throw new TaskException("Error in resuming task with name: " + taskName, TaskException.Code.UNKNOWN, e);
    }
}
 
Example #11
Source File: TriggerUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a list of Dates that are the next fire times of a 
 * <code>Trigger</code>.
 * The input trigger will be cloned before any work is done, so you need
 * not worry about its state being altered by this method.
 * 
 * @param trigg
 *          The trigger upon which to do the work
 * @param cal
 *          The calendar to apply to the trigger's schedule
 * @param numTimes
 *          The number of next fire times to produce
 * @return List of java.util.Date objects
 */
public static List<Date> computeFireTimes(OperableTrigger trigg, org.quartz.Calendar cal,
        int numTimes) {
    LinkedList<Date> lst = new LinkedList<Date>();

    OperableTrigger t = (OperableTrigger) trigg.clone();

    if (t.getNextFireTime() == null) {
        t.computeFirstFireTime(cal);
    }

    for (int i = 0; i < numTimes; i++) {
        Date d = t.getNextFireTime();
        if (d != null) {
            lst.add(d);
            t.triggered(cal);
        } else {
            break;
        }
    }

    return java.util.Collections.unmodifiableList(lst);
}
 
Example #12
Source File: RedisJobStore.java    From redis-quartz with MIT License 6 votes vote down vote up
@Override
public List<OperableTrigger> getTriggersForJob(JobKey jobKey)
		throws JobPersistenceException {
	String jobTriggerSetkey = createJobTriggersSetKey(jobKey.getGroup(), jobKey.getName());
     List<OperableTrigger> triggers = new ArrayList<>();
     try (Jedis jedis = pool.getResource()) {
        lockPool.acquire();
		triggers = getTriggersForJob(jobTriggerSetkey, jedis);
	} catch (Exception ex) {
		log.error("could not get triggers for job_triggers: " + jobTriggerSetkey, ex);
		throw new JobPersistenceException(ex.getMessage(), ex.getCause());
	} finally {
        lockPool.release();
	}
	return triggers;	
}
 
Example #13
Source File: RedisJobStore.java    From redis-quartz with MIT License 6 votes vote down vote up
/**
 * Resume a trigger in redis.
 *
 * @param trigger the trigger
 * @param jedis thread-safe redis connection
 * @throws JobPersistenceException
 */
private void resumeTrigger(OperableTrigger trigger, Jedis jedis) throws JobPersistenceException {
	String triggerHashKey = createTriggerHashKey(trigger.getKey().getGroup(), trigger.getKey().getName());
	if (!jedis.sismember(TRIGGERS_SET, triggerHashKey))
		throw new JobPersistenceException("trigger: " + trigger + " does not exist");
	
	if (jedis.zscore(RedisTriggerState.PAUSED.getKey(), triggerHashKey) == null && jedis.zscore(RedisTriggerState.PAUSED_BLOCKED.getKey(), triggerHashKey) == null)
		throw new JobPersistenceException("trigger: " + trigger + " is not paused");
			
	String jobHashKey = createJobHashKey(trigger.getJobKey().getGroup(), trigger.getJobKey().getName());
	Date nextFireTime = trigger.getNextFireTime();
	if (nextFireTime != null) {
		if (jedis.sismember(BLOCKED_JOBS_SET, jobHashKey))
			setTriggerState(RedisTriggerState.BLOCKED, (double)nextFireTime.getTime(), triggerHashKey);
		else
			setTriggerState(RedisTriggerState.WAITING, (double)nextFireTime.getTime(), triggerHashKey);
	}
}
 
Example #14
Source File: SimpleTriggerPersistenceDelegate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public int updateExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {

        SimpleTrigger simpleTrigger = (SimpleTrigger)trigger;
        
        PreparedStatement ps = null;

        try {
            ps = conn.prepareStatement(Util.rtp(UPDATE_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral));

            ps.setInt(1, simpleTrigger.getRepeatCount());
            ps.setBigDecimal(2, new BigDecimal(String.valueOf(simpleTrigger.getRepeatInterval())));
            ps.setInt(3, simpleTrigger.getTimesTriggered());
            ps.setString(4, simpleTrigger.getKey().getName());
            ps.setString(5, simpleTrigger.getKey().getGroup());

            return ps.executeUpdate();
        } finally {
            Util.closeStatement(ps);
        }
    }
 
Example #15
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void releaseAcquiredTrigger(final OperableTrigger trigger) {
  log.debug("Release acquired trigger: {}", trigger);

  executeWriteAndPropagate(db -> {
    TriggerEntity entity = triggerEntityAdapter.readByKey(db, trigger.getKey());

    // update state to WAITING if the current state is ACQUIRED
    if (entity != null && entity.getState() == ACQUIRED) {
      entity.setState(WAITING);
      triggerEntityAdapter.editEntity(db, entity);
    }

    return null;
  });
}
 
Example #16
Source File: StdJDBCDelegate.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Update a fired trigger.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param trigger
 *          the trigger
 * @param state
 *          the state that the trigger should be stored in
 * @return the number of rows inserted
 */
public int updateFiredTrigger(Connection conn, OperableTrigger trigger,
        String state, JobDetail job) throws SQLException {
    PreparedStatement ps = null;
    try {
        ps = conn.prepareStatement(rtp(UPDATE_FIRED_TRIGGER));
        
        ps.setString(1, instanceId);

        ps.setBigDecimal(2, new BigDecimal(String.valueOf(System.currentTimeMillis())));
        ps.setBigDecimal(3, new BigDecimal(String.valueOf(trigger.getNextFireTime().getTime())));
        ps.setString(4, state);

        if (job != null) {
            ps.setString(5, trigger.getJobKey().getName());
            ps.setString(6, trigger.getJobKey().getGroup());
            setBoolean(ps, 7, job.isConcurrentExectionDisallowed());
            setBoolean(ps, 8, job.requestsRecovery());
        } else {
            ps.setString(5, null);
            ps.setString(6, null);
            setBoolean(ps, 7, false);
            setBoolean(ps, 8, false);
        }

        ps.setString(9, trigger.getFireInstanceId());


        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
Example #17
Source File: StoreTriggerTest.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
@Test
public void replaceTrigger() throws Exception {
    assertFalse(jobStore.replaceTrigger(TriggerKey.triggerKey("foo", "bar"), getCronTrigger()));

    // store triggers and job
    JobDetail job = getJobDetail();
    CronTriggerImpl trigger1 = getCronTrigger("trigger1", "group1", job.getKey());
    CronTriggerImpl trigger2 = getCronTrigger("trigger2", "group1", job.getKey());
    storeJobAndTriggers(job, trigger1, trigger2);

    CronTriggerImpl newTrigger = getCronTrigger("newTrigger", "group1", job.getKey());

    assertTrue(jobStore.replaceTrigger(trigger1.getKey(), newTrigger));

    // ensure that the proper trigger was replaced
    assertThat(jobStore.retrieveTrigger(trigger1.getKey()), nullValue());

    List<OperableTrigger> jobTriggers = jobStore.getTriggersForJob(job.getKey());

    assertThat(jobTriggers, hasSize(2));
    List<TriggerKey> jobTriggerKeys = new ArrayList<>(jobTriggers.size());
    for (OperableTrigger jobTrigger : jobTriggers) {
        jobTriggerKeys.add(jobTrigger.getKey());
    }

    assertThat(jobTriggerKeys, containsInAnyOrder(trigger2.getKey(), newTrigger.getKey()));
}
 
Example #18
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Resume (un-pause) the <code>{@link Trigger}</code> with the given
 * key.
 * </p>
 *
 * <p>
 * If the <code>Trigger</code> missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 *
 */
public void resumeTrigger(TriggerKey triggerKey) {

    synchronized (lock) {
        TriggerWrapper tw = triggersByKey.get(triggerKey);

        // does the trigger exist?
        if (tw == null || tw.trigger == null) {
            return;
        }

        OperableTrigger trig = tw.getTrigger();

        // if the trigger is not paused resuming it does not make sense...
        if (tw.state != TriggerWrapper.STATE_PAUSED &&
                tw.state != TriggerWrapper.STATE_PAUSED_BLOCKED) {
            return;
        }

        if(blockedJobs.contains( trig.getJobKey() )) {
            tw.state = TriggerWrapper.STATE_BLOCKED;
        } else {
            tw.state = TriggerWrapper.STATE_WAITING;
        }

        applyMisfire(tw);

        if (tw.state == TriggerWrapper.STATE_WAITING) {
            timeTriggers.add(tw);
        }
    }
}
 
Example #19
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Schedule the given <code>{@link org.quartz.Trigger}</code> with the
 * <code>Job</code> identified by the <code>Trigger</code>'s settings.
 * </p>
 * 
 * @throws SchedulerException
 *           if the indicated Job does not exist, or the Trigger cannot be
 *           added to the Scheduler, or there is an internal Scheduler
 *           error.
 */
public Date scheduleJob(Trigger trigger)
    throws SchedulerException {
    validateState();

    if (trigger == null) {
        throw new SchedulerException("Trigger cannot be null");
    }

    OperableTrigger trig = (OperableTrigger)trigger;
    
    trig.validate();

    Calendar cal = null;
    if (trigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(trigger.getCalendarName());
        if(cal == null) {
            throw new SchedulerException(
                "Calendar not found: " + trigger.getCalendarName());
        }
    }
    Date ft = trig.computeFirstFireTime(cal);

    if (ft == null) {
        throw new SchedulerException(
                "Based on configured schedule, the given trigger '" + trigger.getKey() + "' will never fire.");
    }

    resources.getJobStore().storeTrigger(trig, false);
    notifySchedulerThread(trigger.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trigger);

    return ft;
}
 
Example #20
Source File: QuartzSchedulerThread.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean releaseIfScheduleChangedSignificantly(
        List<OperableTrigger> triggers, long triggerTime) {
    if (isCandidateNewTimeEarlierWithinReason(triggerTime, true)) {
        // above call does a clearSignaledSchedulingChange()
        for (OperableTrigger trigger : triggers) {
            qsRsrcs.getJobStore().releaseAcquiredTrigger(trigger);
        }
        triggers.clear();
        return true;
    }
    return false;
}
 
Example #21
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Pause the <code>{@link org.quartz.JobDetail}</code> with the given
 * name - by pausing all of its current <code>Trigger</code>s.
 * </p>
 *
 */
public void pauseJob(JobKey jobKey) {
    synchronized (lock) {
        List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey);
        for (OperableTrigger trigger: triggersOfJob) {
            pauseTrigger(trigger.getKey());
        }
    }
}
 
Example #22
Source File: TriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(Map<String, Object> attrMap) throws ParseException {
    OperableTrigger result = null;
    if(attrMap.containsKey("cronExpression")) {
        result = CronTriggerSupport.newTrigger(attrMap);
    } else {
        result = SimpleTriggerSupport.newTrigger(attrMap);
    }
    return result;
}
 
Example #23
Source File: TriggerUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a list of Dates that are the next fire times of a 
 * <code>Trigger</code>
 * that fall within the given date range. The input trigger will be cloned
 * before any work is done, so you need not worry about its state being
 * altered by this method.
 * 
 * <p>
 * NOTE: if this is a trigger that has previously fired within the given
 * date range, then firings which have already occurred will not be listed
 * in the output List.
 * </p>
 * 
 * @param trigg
 *          The trigger upon which to do the work
 * @param cal
 *          The calendar to apply to the trigger's schedule
 * @param from
 *          The starting date at which to find fire times
 * @param to
 *          The ending date at which to stop finding fire times
 * @return List of java.util.Date objects
 */
public static List<Date> computeFireTimesBetween(OperableTrigger trigg,
        org.quartz.Calendar cal, Date from, Date to) {
    LinkedList<Date> lst = new LinkedList<Date>();

    OperableTrigger t = (OperableTrigger) trigg.clone();

    if (t.getNextFireTime() == null) {
        t.setStartTime(from);
        t.setEndTime(to);
        t.computeFirstFireTime(cal);
    }

    while (true) {
        Date d = t.getNextFireTime();
        if (d != null) {
            if (d.before(from)) {
                t.triggered(cal);
                continue;
            }
            if (d.after(to)) {
                break;
            }
            lst.add(d);
            t.triggered(cal);
        } else {
            break;
        }
    }

    return java.util.Collections.unmodifiableList(lst);
}
 
Example #24
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
protected boolean applyMisfire(OperableTrigger trigger, Jedis jedis) throws JobPersistenceException {
   long misfireTime = System.currentTimeMillis();
   if (getMisfireThreshold() > 0)
       misfireTime -= getMisfireThreshold();       

   Date triggerNextFireTime = trigger.getNextFireTime();
   if (triggerNextFireTime == null || triggerNextFireTime.getTime() > misfireTime 
           || trigger.getMisfireInstruction() == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { 
       return false; 
   }

   Calendar cal = null;
   if (trigger.getCalendarName() != null)
       cal = retrieveCalendar(trigger.getCalendarName(), jedis);       

   signaler.notifyTriggerListenersMisfired((OperableTrigger)trigger.clone());

   trigger.updateAfterMisfire(cal);
   
   if (triggerNextFireTime.equals(trigger.getNextFireTime()))
	   return false;

   storeTrigger(trigger, true, jedis);
   if (trigger.getNextFireTime() == null) { // Trigger completed
	   setTriggerState(RedisTriggerState.COMPLETED, (double)System.currentTimeMillis(), createTriggerHashKey(trigger.getKey().getGroup(), trigger.getKey().getName()));
	   signaler.notifySchedulerListenersFinalized(trigger);
   }
   
   return true;
}
 
Example #25
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * @see org.quartz.spi.JobStore#replaceTrigger(TriggerKey, OperableTrigger)
 */
public boolean replaceTrigger(final TriggerKey triggerKey, 
        final OperableTrigger newTrigger) throws JobPersistenceException {
    return (Boolean) executeInLock(
            LOCK_TRIGGER_ACCESS,
            new TransactionCallback() {
                public Object execute(Connection conn) throws JobPersistenceException {
                    return replaceTrigger(conn, triggerKey, newTrigger) ?
                            Boolean.TRUE : Boolean.FALSE;
                }
            });
}
 
Example #26
Source File: TriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(CompositeData cData) throws ParseException {
    OperableTrigger result = null;
    if(cData.containsKey("cronExpression")) {
        result = CronTriggerSupport.newTrigger(cData);
    } else {
        result = SimpleTriggerSupport.newTrigger(cData);
    }
    return result;
}
 
Example #27
Source File: SimpleTriggerSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static OperableTrigger newTrigger(Map<String, Object> attrMap) throws ParseException {
    SimpleTriggerImpl result = new SimpleTriggerImpl();
    if(attrMap.containsKey("repeatCount")) {
        result.setRepeatCount(((Integer) attrMap.get("repeatCount")).intValue());
    }
    if(attrMap.containsKey("repeatInterval")) {
        result.setRepeatInterval(((Long) attrMap.get("repeatInterval")).longValue());
    }
    if(attrMap.containsKey("timesTriggered")) {
        result.setTimesTriggered(((Integer) attrMap.get("timesTriggered")).intValue());
    }
    TriggerSupport.initializeTrigger(result, attrMap);
    return result;
}
 
Example #28
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected OperableTrigger retrieveTrigger(Connection conn, TriggerKey key)
    throws JobPersistenceException {
    try {

        return getDelegate().selectTrigger(conn, key);
    } catch (Exception e) {
        throw new JobPersistenceException("Couldn't retrieve trigger: "
                + e.getMessage(), e);
    }
}
 
Example #29
Source File: RedisClusterStorage.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Store a {@link Calendar}
 *
 * @param name            the name of the calendar
 * @param calendar        the calendar object to be stored
 * @param replaceExisting if true, any existing calendar with the same name will be overwritten
 * @param updateTriggers  if true, any existing triggers associated with the calendar will be updated
 * @param jedis           a thread-safe Redis connection
 * @throws JobPersistenceException
 */
@Override
public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers, JedisClusterCommandsWrapper jedis) throws JobPersistenceException {
    final String calendarHashKey = redisSchema.calendarHashKey(name);
    if (!replaceExisting && jedis.exists(calendarHashKey)) {
        throw new ObjectAlreadyExistsException(String.format("Calendar with key %s already exists.", calendarHashKey));
    }
    Map<String, String> calendarMap = new HashMap<>();
    calendarMap.put(CALENDAR_CLASS, calendar.getClass().getName());
    try {
        calendarMap.put(CALENDAR_JSON, mapper.writeValueAsString(calendar));
    } catch (JsonProcessingException e) {
        throw new JobPersistenceException("Unable to serialize calendar.", e);
    }

    jedis.hmset(calendarHashKey, calendarMap);
    jedis.sadd(redisSchema.calendarsSet(), calendarHashKey);

    if (updateTriggers) {
        final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(name);
        Set<String> triggerHashKeys = jedis.smembers(calendarTriggersSetKey);
        for (String triggerHashKey : triggerHashKeys) {
            OperableTrigger trigger = retrieveTrigger(redisSchema.triggerKey(triggerHashKey), jedis);
            long removed = jedis.zrem(redisSchema.triggerStateKey(RedisTriggerState.WAITING), triggerHashKey);
            trigger.updateWithNewCalendar(calendar, misfireThreshold);
            if (removed == 1) {
                setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis);
            }
        }
    }
}
 
Example #30
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void jobToBeExecuted(JobExecutionContext context) {
    numJobsFired.incrementAndGet();

    synchronized (executingJobs) {
        executingJobs
                .put(((OperableTrigger)context.getTrigger()).getFireInstanceId(), context);
    }
}