Java 类org.quartz.spi.OperableTrigger 实例源码

项目:lams    文件:CalendarIntervalTriggerPersistenceDelegate.java   
@Override
protected SimplePropertiesTriggerProperties getTriggerProperties(OperableTrigger trigger) {

    CalendarIntervalTriggerImpl calTrig = (CalendarIntervalTriggerImpl)trigger;

    SimplePropertiesTriggerProperties props = new SimplePropertiesTriggerProperties();

    props.setInt1(calTrig.getRepeatInterval());
    props.setString1(calTrig.getRepeatIntervalUnit().name());
    props.setInt2(calTrig.getTimesTriggered());
    props.setString2(calTrig.getTimeZone().getID());
    props.setBoolean1(calTrig.isPreserveHourOfDayAcrossDaylightSavings());
    props.setBoolean2(calTrig.isSkipDayIfHourDoesNotExist());

    return props;
}
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the given group - by pausing all of their
 * <code>Trigger</code>s.
 * </p>
 * <p>
 * The JobStore should "remember" that the group is paused, and impose the pause on any new jobs that are added to the
 * group while the group is paused.
 * </p>
 */
@Override
public Collection<String> pauseJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException {
  Collection<String> pausedGroups = new HashSet<String>();
  lock();
  try {

    Set<JobKey> jobKeys = getJobKeys(matcher);

    for (JobKey jobKey : jobKeys) {
      for (OperableTrigger trigger : getTriggersForJob(jobKey)) {
        pauseTrigger(trigger.getKey());
      }
      pausedGroups.add(jobKey.getGroup());
    }
    // make sure to account for an exact group match for a group that doesn't yet exist
    StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
    if (operator.equals(StringOperatorName.EQUALS)) {
      jobFacade.addPausedGroup(matcher.getCompareToValue());
      pausedGroups.add(matcher.getCompareToValue());
    }
  } finally {
    unlock();
  }
  return pausedGroups;
}
项目:lams    文件:SimpleTriggerPersistenceDelegate.java   
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);
        }
    }
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * <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;
}
项目:lams    文件:DefaultClusteredJobStore.java   
@Override
public List<OperableTrigger> acquireNextTriggers(long noLaterThan, int maxCount, long timeWindow)
    throws JobPersistenceException {
  List<OperableTrigger> result = new ArrayList<OperableTrigger>();;
  lock();
  try {
    for (TriggerWrapper tw : getNextTriggerWrappers(timeTriggers, noLaterThan, maxCount, timeWindow)) {
      result.add(markAndCloneTrigger(tw));
    }
    return result;
  } finally {
    try {
      unlock();
    } catch (RejoinException e) {
      if (!validateAcquired(result)) {
        throw e;
      }
    }
  }
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Trigger the identified <code>{@link org.quartz.Job}</code> (execute it
 * now) - with a non-volatile trigger.
 * </p>
 */
@SuppressWarnings("deprecation")
public void triggerJob(JobKey jobKey, JobDataMap data) throws SchedulerException {
    validateState();

    OperableTrigger trig = (OperableTrigger) newTrigger().withIdentity(newTriggerId(), Scheduler.DEFAULT_GROUP).forJob(jobKey).build();
    trig.computeFirstFireTime(null);
    if(data != null) {
        trig.setJobDataMap(data);
    }

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <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;
}
项目:lams    文件:TriggerUtils.java   
/**
 * 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);
}
项目:lams    文件:RAMJobStore.java   
/**
 * <p>
 * Remove (delete) the <code>{@link org.quartz.Calendar}</code> with the
 * given name.
 * </p>
 *
 * <p>
 * If removal of the <code>Calendar</code> would result in
 * <code>Trigger</code>s pointing to non-existent calendars, then a
 * <code>JobPersistenceException</code> will be thrown.</p>
 *       *
 * @param calName The name of the <code>Calendar</code> to be removed.
 * @return <code>true</code> if a <code>Calendar</code> with the given name
 * was found and removed from the store.
 */
public boolean removeCalendar(String calName)
    throws JobPersistenceException {
    int numRefs = 0;

    synchronized (lock) {
        for (TriggerWrapper trigger : triggers) {
            OperableTrigger trigg = trigger.trigger;
            if (trigg.getCalendarName() != null
                    && trigg.getCalendarName().equals(calName)) {
                numRefs++;
            }
        }
    }

    if (numRefs > 0) {
        throw new JobPersistenceException(
                "Calender cannot be removed if it referenced by a Trigger!");
    }

    return (calendarsByName.remove(calName) != null);
}
项目:lams    文件:SimpleTriggerSupport.java   
public static CompositeData toCompositeData(SimpleTrigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getRepeatCount(),
                        trigger.getRepeatInterval(),
                        trigger.getTimesTriggered(),
                        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);
    }
}
项目:lams    文件:RAMJobStore.java   
protected boolean applyMisfire(TriggerWrapper tw) {

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

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

        Calendar cal = null;
        if (tw.trigger.getCalendarName() != null) {
            cal = retrieveCalendar(tw.trigger.getCalendarName());
        }

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

        tw.trigger.updateAfterMisfire(cal);

        if (tw.trigger.getNextFireTime() == null) {
            tw.state = TriggerWrapper.STATE_COMPLETE;
            signaler.notifySchedulerListenersFinalized(tw.trigger);
            synchronized (lock) {
                timeTriggers.remove(tw);
            }
        } else if (tnft.equals(tw.trigger.getNextFireTime())) {
            return false;
        }

        return true;
    }
项目:lams    文件:JobStoreSupport.java   
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);
    }
}
项目:lams    文件:JobStoreSupport.java   
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);
    }
}
项目:lams    文件:JobStoreSupport.java   
public void storeJobsAndTriggers(
        final Map<JobDetail, Set<? extends Trigger>> triggersAndJobs, final boolean replace)
        throws JobPersistenceException {

    executeInLock(
            (isLockOnInsert() || replace) ? LOCK_TRIGGER_ACCESS : null,
            new VoidTransactionCallback() {
                public void executeVoid(Connection conn) throws JobPersistenceException {

                    // FUTURE_TODO: make this more efficient with a true bulk operation...
                    for(JobDetail job: triggersAndJobs.keySet()) {
                        storeJob(conn, job, replace);
                        for(Trigger trigger: triggersAndJobs.get(job)) {
                            storeTrigger(conn, (OperableTrigger) trigger, job, replace,
                                    Constants.STATE_WAITING, false, false);
                        }
                    }
                }
            });
}
项目:lams    文件:JobStoreSupport.java   
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.Job}s</code> matching the given
 * groupMatcher - by pausing all of their <code>Trigger</code>s.
 * </p>
 * 
 * @see #resumeJobs(org.quartz.impl.matchers.GroupMatcher)
 */
@SuppressWarnings("unchecked")
public Set<String> pauseJobs(final GroupMatcher<JobKey> matcher)
    throws JobPersistenceException {
    return (Set<String>) executeInLock(
        LOCK_TRIGGER_ACCESS,
        new TransactionCallback() {
            public Set<String> execute(final Connection conn) throws JobPersistenceException {
                Set<String> groupNames = new HashSet<String>();
                Set<JobKey> jobNames = getJobNames(conn, matcher);

                for (JobKey jobKey : jobNames) {
                    List<OperableTrigger> triggers = getTriggersForJob(conn, jobKey);
                    for (OperableTrigger trigger : triggers) {
                        pauseTrigger(conn, trigger.getKey());
                    }
                    groupNames.add(jobKey.getGroup());
                }

                return groupNames;
            }
        }
        );
}
项目:lams    文件:JobStoreSupport.java   
/**
 * <p>
 * Resume (un-pause) all of the <code>{@link org.quartz.Job}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>
 * 
 * @see #pauseJobs(org.quartz.impl.matchers.GroupMatcher)
 */
@SuppressWarnings("unchecked")
public Set<String> resumeJobs(final GroupMatcher<JobKey> matcher)
    throws JobPersistenceException {
    return (Set<String>) executeInLock(
        LOCK_TRIGGER_ACCESS,
        new TransactionCallback() {
            public Set<String> execute(Connection conn) throws JobPersistenceException {
                Set<JobKey> jobKeys = getJobNames(conn, matcher);
                Set<String> groupNames = new HashSet<String>();

                for (JobKey jobKey: jobKeys) {
                    List<OperableTrigger> triggers = getTriggersForJob(conn, jobKey);
                    for (OperableTrigger trigger: triggers) {
                        resumeTrigger(conn, trigger.getKey());
                    }
                    groupNames.add(jobKey.getGroup());
                }
                return groupNames;
            }
        });
}
项目:lams    文件:QuartzScheduler.java   
/**
 * <p>
 * Store and schedule the identified <code>{@link org.quartz.spi.OperableTrigger}</code>
 * </p>
 */
public void triggerJob(OperableTrigger trig) throws SchedulerException {
    validateState();

    trig.computeFirstFireTime(null);

    boolean collision = true;
    while (collision) {
        try {
            resources.getJobStore().storeTrigger(trig, false);
            collision = false;
        } catch (ObjectAlreadyExistsException oaee) {
            trig.setKey(new TriggerKey(newTriggerId(), Scheduler.DEFAULT_GROUP));
        }
    }

    notifySchedulerThread(trig.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trig);
}
项目:lams    文件:CronTriggerSupport.java   
public static CompositeData toCompositeData(CronTrigger trigger) {
    try {
        return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
                new Object[] {
                        trigger.getCronExpression(),
                        trigger.getTimeZone(),
                        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);
    }
}
项目:lams    文件:CronTriggerPersistenceDelegate.java   
public int updateExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {

        CronTrigger cronTrigger = (CronTrigger)trigger;

        PreparedStatement ps = null;

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

            return ps.executeUpdate();
        } finally {
            Util.closeStatement(ps);
        }
    }
项目:lams    文件:StdJDBCDelegate.java   
public List<OperableTrigger> selectTriggersForCalendar(Connection conn, String calName)
    throws SQLException, ClassNotFoundException, IOException, JobPersistenceException {

    LinkedList<OperableTrigger> trigList = new LinkedList<OperableTrigger>();
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        ps = conn.prepareStatement(rtp(SELECT_TRIGGERS_FOR_CALENDAR));
        ps.setString(1, calName);
        rs = ps.executeQuery();

        while (rs.next()) {
            trigList.add(selectTrigger(conn, triggerKey(rs.getString(COL_TRIGGER_NAME), rs.getString(COL_TRIGGER_GROUP))));
        }
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
    }

    return trigList;
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public List<OperableTrigger> acquireNextTriggers(long noLaterThan, int maxCount, long timeWindow)
    throws JobPersistenceException {
  try {
    return realJobStore.acquireNextTriggers(noLaterThan, maxCount, timeWindow);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Trigger acquisition failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public List<OperableTrigger> getTriggersForJob(JobKey jobKey) throws JobPersistenceException {
  try {
    return realJobStore.getTriggersForJob(jobKey);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Trigger retrieval failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public boolean replaceTrigger(TriggerKey triggerKey, OperableTrigger newTrigger) throws JobPersistenceException {
  try {
    return realJobStore.replaceTrigger(triggerKey, newTrigger);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Replacing trigger failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public OperableTrigger retrieveTrigger(TriggerKey triggerKey) throws JobPersistenceException {
  try {
    return realJobStore.retrieveTrigger(triggerKey);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Trigger retrieval failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public void storeJobAndTrigger(JobDetail newJob, OperableTrigger newTrigger) throws ObjectAlreadyExistsException,
    JobPersistenceException {
  try {
    realJobStore.storeJobAndTrigger(newJob, newTrigger);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Storing job and trigger failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public void storeTrigger(OperableTrigger newTrigger, boolean replaceExisting) throws ObjectAlreadyExistsException,
    JobPersistenceException {
  try {
    realJobStore.storeTrigger(newTrigger, replaceExisting);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Storing trigger failed due to client rejoin", e);
  }
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public void triggeredJobComplete(OperableTrigger trigger, JobDetail jobDetail, Trigger.CompletedExecutionInstruction instruction) {
  realJobStore.triggeredJobComplete(trigger, jobDetail, instruction);
}
项目:lams    文件:AbstractTerracottaJobStore.java   
@Override
public List<TriggerFiredResult> triggersFired(List<OperableTrigger> triggers) throws JobPersistenceException {
  try {
    return realJobStore.triggersFired(triggers);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Trigger fire marking failed due to client rejoin", e);
  }
}
项目:lams    文件:DefaultClusteredJobStore.java   
protected OperableTrigger createRecoveryTrigger(TriggerWrapper tw, JobWrapper jw,
                                                String name, FiredTrigger recovering) {
  final SimpleTriggerImpl recoveryTrigger = new SimpleTriggerImpl(name, Scheduler.DEFAULT_RECOVERY_GROUP, new Date(recovering.getScheduledFireTime()));
  recoveryTrigger.setJobName(jw.getKey().getName());
  recoveryTrigger.setJobGroup(jw.getKey().getGroup());
  recoveryTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY);
  recoveryTrigger.setPriority(tw.getPriority());
  return recoveryTrigger;
}
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * <p>
 * Remove (delete) the <code>{@link org.quartz.Job}</code> with the given name, and any
 * <code>{@link org.quartz.Trigger}</code> s that reference it.
 * </p>
 * 
 * @param jobKey The key of the <code>Job</code> to be removed.
 * @return <code>true</code> if a <code>Job</code> with the given name & group was found and removed from the store.
 */
@Override
public boolean removeJob(JobKey jobKey) throws JobPersistenceException {
  boolean found = false;
  lock();
  try {
    List<OperableTrigger> trigger = getTriggersForJob(jobKey);
    for (OperableTrigger trig : trigger) {
      this.removeTrigger(trig.getKey());
      found = true;
    }

    found = (jobFacade.remove(jobKey) != null) | found;
    if (found) {
      Set<String> grpSet = toolkitDSHolder.getOrCreateJobsGroupMap(jobKey.getGroup());
      grpSet.remove(jobKey.getName());
      if (grpSet.isEmpty()) {
        toolkitDSHolder.removeJobsGroupMap(jobKey.getGroup());
        jobFacade.removeGroup(jobKey.getGroup());
      }
    }
  } finally {
    unlock();
  }

  return found;
}
项目:lams    文件:DefaultClusteredJobStore.java   
private boolean removeTrigger(TriggerKey triggerKey, boolean removeOrphanedJob) throws JobPersistenceException {

    lock();
    TriggerWrapper tw = null;
    try {
      // remove from triggers by FQN map
      tw = triggerFacade.remove(triggerKey);

      if (tw != null) {
        // remove from triggers by group
        Set<String> grpSet = toolkitDSHolder.getOrCreateTriggersGroupMap(triggerKey.getGroup());
        grpSet.remove(triggerKey.getName());
        if (grpSet.size() == 0) {
          toolkitDSHolder.removeTriggersGroupMap(triggerKey.getGroup());
          triggerFacade.removeGroup(triggerKey.getGroup());
        }
        // remove from triggers array
        timeTriggers.remove(tw);

        if (removeOrphanedJob) {
          JobWrapper jw = jobFacade.get(tw.getJobKey());
          List<OperableTrigger> trigs = getTriggersForJob(tw.getJobKey());
          if ((trigs == null || trigs.size() == 0) && !jw.isDurable()) {
            JobKey jobKey = tw.getJobKey();
            if (removeJob(jobKey)) {
              signaler.notifySchedulerListenersJobDeleted(jobKey);
            }
          }
        }
      }
    } finally {
      unlock();
    }

    return tw != null;
  }
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * @see org.quartz.spi.JobStore#replaceTrigger
 */
@Override
public boolean replaceTrigger(TriggerKey triggerKey, OperableTrigger newTrigger) throws JobPersistenceException {
  boolean found = false;

  lock();
  try {
    // remove from triggers by FQN map
    TriggerWrapper tw = triggerFacade.remove(triggerKey);
    found = tw != null;

    if (tw != null) {
      if (!tw.getJobKey().equals(newTrigger.getJobKey())) { throw new JobPersistenceException(
                                                                                              "New trigger is not related to the same job as the old trigger."); }
      // remove from triggers by group
      Set<String> grpSet = toolkitDSHolder.getOrCreateTriggersGroupMap(triggerKey.getGroup());
      grpSet.remove(triggerKey.getName());
      if (grpSet.size() == 0) {
        toolkitDSHolder.removeTriggersGroupMap(triggerKey.getGroup());
        triggerFacade.removeGroup(triggerKey.getGroup());
      }
      timeTriggers.remove(tw);

      try {
        storeTrigger(newTrigger, false);
      } catch (JobPersistenceException jpe) {
        storeTrigger(tw.getTriggerClone(), false); // put previous trigger back...
        throw jpe;
      }
    }
  } finally {
    unlock();
  }

  return found;
}
项目:lams    文件:DefaultClusteredJobStore.java   
/**
 * <p>
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 * </p>
 * 
 * @param triggerKey The key of the <code>Trigger</code> to be retrieved.
 * @return The desired <code>Trigger</code>, or null if there is no match.
 */
@Override
public OperableTrigger retrieveTrigger(TriggerKey triggerKey) throws JobPersistenceException {
  lock();
  try {
    TriggerWrapper tw = triggerFacade.get(triggerKey);
    return (tw != null) ? (OperableTrigger) tw.getTriggerClone() : null;
  } finally {
    unlock();
  }
}
项目:lams    文件:QuartzSchedulerThread.java   
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;
}
项目:lams    文件:DefaultClusteredJobStore.java   
OperableTrigger markAndCloneTrigger(final TriggerWrapper tw) {
  tw.setState(TriggerState.ACQUIRED, terracottaClientId, triggerFacade);

  String firedInstanceId = terracottaClientId + "-" + String.valueOf(ftrCtr++);
  tw.setFireInstanceId(firedInstanceId, triggerFacade);

  return tw.getTriggerClone();
}
项目:lams    文件:TriggerSupport.java   
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;
}
项目:lams    文件:TriggerWrapper.java   
protected TriggerWrapper(OperableTrigger trigger, boolean jobDisallowsConcurrence) {
  this.trigger = trigger;
  this.jobDisallowsConcurrence = jobDisallowsConcurrence;

  // TriggerWrapper instances get shared in many collections and the serialized form
  // might be referenced before this wrapper makes it into the "timeTriggers" set
  // DEV-4807
  // serialize(serializer);
}
项目:lams    文件:RAMJobStore.java   
/**
 * <p>
 * Get all of the Triggers that are associated to the given Job.
 * </p>
 *
 * <p>
 * If there are no matches, a zero-length array should be returned.
 * </p>
 */
public List<OperableTrigger> getTriggersForJob(JobKey jobKey) {
    ArrayList<OperableTrigger> trigList = new ArrayList<OperableTrigger>();

    synchronized (lock) {
        for (TriggerWrapper tw : triggers) {
            if (tw.jobKey.equals(jobKey)) {
                trigList.add((OperableTrigger) tw.trigger.clone());
            }
        }
    }

    return trigList;
}
项目:lams    文件:RAMJobStore.java   
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the
 * given group - by pausing all of their <code>Trigger</code>s.
 * </p>
 *
 *
 * <p>
 * The JobStore should "remember" that the group is paused, and impose the
 * pause on any new jobs that are added to the group while the group is
 * paused.
 * </p>
 */
public List<String> pauseJobs(GroupMatcher<JobKey> matcher) {
    List<String> pausedGroups = new LinkedList<String>();
    synchronized (lock) {

        StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
        switch (operator) {
            case EQUALS:
                if (pausedJobGroups.add(matcher.getCompareToValue())) {
                    pausedGroups.add(matcher.getCompareToValue());
                }
                break;
            default :
                for (String group : jobsByGroup.keySet()) {
                    if(operator.evaluate(group, matcher.getCompareToValue())) {
                        if (pausedJobGroups.add(group)) {
                            pausedGroups.add(group);
                        }
                    }
                }
        }

        for (String groupName : pausedGroups) {
            for (JobKey jobKey: getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
                List<OperableTrigger> triggersOfJob = getTriggersForJob(jobKey);
                for (OperableTrigger trigger: triggersOfJob) {
                    pauseTrigger(trigger.getKey());
                }
            }
        }
    }

    return pausedGroups;
}
项目:lams    文件:RAMJobStore.java   
/**
 * <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);
        }
    }
}