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

The following examples show how to use org.quartz.spi.OperableTrigger#clone() . 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: 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 2
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 3
Source File: TaskNode.java    From uflo with Apache License 2.0 5 votes vote down vote up
public static Date computeFireTimesWithStart(OperableTrigger trigg,org.quartz.Calendar cal, Date from) {
    OperableTrigger t = (OperableTrigger) trigg.clone();
    if (t.getNextFireTime() == null) {
        t.setStartTime(from);
        t.computeFirstFireTime(cal);
    }
    return t.getNextFireTime();
}
 
Example 4
Source File: SimpleScheduleJobService.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
public static List<Date> computeFireTimesBetween(OperableTrigger trigger,
                                                 org.quartz.Calendar cal, Date from, Date to, int num) {
    List<Date> lst = new LinkedList<>();
    OperableTrigger t = (OperableTrigger) trigger.clone();
    if (t.getNextFireTime() == null) {
        t.setStartTime(from);
        t.setEndTime(to);
        t.computeFirstFireTime(cal);
    }
    for (int i = 0; i < num; i++) {
        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 lst;
}
 
Example 5
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>
 * Store the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 * 
 * @param newTrigger The <code>Trigger</code> to be stored.
 * @param replaceExisting If <code>true</code>, any <code>Trigger</code> existing in the <code>JobStore</code> with
 *        the same name & group should be over-written.
 * @throws ObjectAlreadyExistsException if a <code>Trigger</code> with the same name/group already exists, and
 *         replaceExisting is set to false.
 * @see #pauseTriggers(org.quartz.impl.matchers.GroupMatcher)
 */
@Override
public void storeTrigger(OperableTrigger newTrigger, boolean replaceExisting) throws JobPersistenceException {
  OperableTrigger clone = (OperableTrigger) newTrigger.clone();

  lock();
  try {
    JobDetail job = retrieveJob(newTrigger.getJobKey());
    if (job == null) {
      //
      throw new JobPersistenceException("The job (" + newTrigger.getJobKey()
                                        + ") referenced by the trigger does not exist.");
    }

    // wrapper construction must be done in lock since serializer is unlocked
    TriggerWrapper tw = wrapperFactory.createTriggerWrapper(clone, job.isConcurrentExectionDisallowed());

    if (triggerFacade.containsKey(tw.getKey())) {
      if (!replaceExisting) { throw new ObjectAlreadyExistsException(newTrigger); }

      removeTrigger(newTrigger.getKey(), false);
    }

    // add to triggers by group
    Set<String> grpSet = toolkitDSHolder.getOrCreateTriggersGroupMap(newTrigger.getKey().getGroup());
    grpSet.add(newTrigger.getKey().getName());
    if (!triggerFacade.hasGroup(newTrigger.getKey().getGroup())) {
      triggerFacade.addGroup(newTrigger.getKey().getGroup());
    }

    if (triggerFacade.pausedGroupsContain(newTrigger.getKey().getGroup())
        || jobFacade.pausedGroupsContain(newTrigger.getJobKey().getGroup())) {
      tw.setState(TriggerState.PAUSED, terracottaClientId, triggerFacade);
      if (jobFacade.blockedJobsContain(tw.getJobKey())) {
        tw.setState(TriggerState.PAUSED_BLOCKED, terracottaClientId, triggerFacade);
      }
    } else if (jobFacade.blockedJobsContain(tw.getJobKey())) {
      tw.setState(TriggerState.BLOCKED, terracottaClientId, triggerFacade);
    } else {
      timeTriggers.add(tw);
    }

    // add to triggers by FQN map
    triggerFacade.put(tw.getKey(), tw);
  } finally {
    unlock();
  }
}
 
Example 6
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <p>
 * Store the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 *
 * @param newTrigger
 *          The <code>Trigger</code> to be stored.
 * @param replaceExisting
 *          If <code>true</code>, any <code>Trigger</code> existing in
 *          the <code>JobStore</code> with the same name & group should
 *          be over-written.
 * @throws ObjectAlreadyExistsException
 *           if a <code>Trigger</code> with the same name/group already
 *           exists, and replaceExisting is set to false.
 *
 * @see #pauseTriggers(org.quartz.impl.matchers.GroupMatcher)
 */
public void storeTrigger(OperableTrigger newTrigger,
        boolean replaceExisting) throws JobPersistenceException {
    TriggerWrapper tw = new TriggerWrapper((OperableTrigger)newTrigger.clone());

    synchronized (lock) {
        if (triggersByKey.get(tw.key) != null) {
            if (!replaceExisting) {
                throw new ObjectAlreadyExistsException(newTrigger);
            }

            removeTrigger(newTrigger.getKey(), false);
        }

        if (retrieveJob(newTrigger.getJobKey()) == null) {
            throw new JobPersistenceException("The job ("
                    + newTrigger.getJobKey()
                    + ") referenced by the trigger does not exist.");
        }

        // add to triggers array
        triggers.add(tw);
        // add to triggers by group
        HashMap<TriggerKey, TriggerWrapper> grpMap = triggersByGroup.get(newTrigger.getKey().getGroup());
        if (grpMap == null) {
            grpMap = new HashMap<TriggerKey, TriggerWrapper>(100);
            triggersByGroup.put(newTrigger.getKey().getGroup(), grpMap);
        }
        grpMap.put(newTrigger.getKey(), tw);
        // add to triggers by FQN map
        triggersByKey.put(tw.key, tw);

        if (pausedTriggerGroups.contains(newTrigger.getKey().getGroup())
                || pausedJobGroups.contains(newTrigger.getJobKey().getGroup())) {
            tw.state = TriggerWrapper.STATE_PAUSED;
            if (blockedJobs.contains(tw.jobKey)) {
                tw.state = TriggerWrapper.STATE_PAUSED_BLOCKED;
            }
        } else if (blockedJobs.contains(tw.jobKey)) {
            tw.state = TriggerWrapper.STATE_BLOCKED;
        } else {
            timeTriggers.add(tw);
        }
    }
}