当前位置: 首页>>代码示例>>Java>>正文


Java OperableTrigger.setJobKey方法代码示例

本文整理汇总了Java中org.quartz.spi.OperableTrigger.setJobKey方法的典型用法代码示例。如果您正苦于以下问题:Java OperableTrigger.setJobKey方法的具体用法?Java OperableTrigger.setJobKey怎么用?Java OperableTrigger.setJobKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.quartz.spi.OperableTrigger的用法示例。


在下文中一共展示了OperableTrigger.setJobKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scheduleJob

import org.quartz.spi.OperableTrigger; //导入方法依赖的package包/类
/**
 * <p>
 * Add the <code>{@link org.quartz.Job}</code> identified by the given
 * <code>{@link org.quartz.JobDetail}</code> to the Scheduler, and
 * associate the given <code>{@link org.quartz.Trigger}</code> with it.
 * </p>
 * 
 * <p>
 * If the given Trigger does not reference any <code>Job</code>, then it
 * will be set to reference the Job passed with it into this method.
 * </p>
 * 
 * @throws SchedulerException
 *           if the Job or Trigger cannot be added to the Scheduler, or
 *           there is an internal Scheduler error.
 */
public Date scheduleJob(JobDetail jobDetail,
        Trigger trigger) throws SchedulerException {
    validateState();

    if (jobDetail == null) {
        throw new SchedulerException("JobDetail cannot be null");
    }
    
    if (trigger == null) {
        throw new SchedulerException("Trigger cannot be null");
    }
    
    if (jobDetail.getKey() == null) {
        throw new SchedulerException("Job's key cannot be null");
    }

    if (jobDetail.getJobClass() == null) {
        throw new SchedulerException("Job's class cannot be null");
    }
    
    OperableTrigger trig = (OperableTrigger)trigger;

    if (trigger.getJobKey() == null) {
        trig.setJobKey(jobDetail.getKey());
    } else if (!trigger.getJobKey().equals(jobDetail.getKey())) {
        throw new SchedulerException(
            "Trigger does not reference given job!");
    }

    trig.validate();

    Calendar cal = null;
    if (trigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(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().storeJobAndTrigger(jobDetail, trig);
    notifySchedulerListenersJobAdded(jobDetail);
    notifySchedulerThread(trigger.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trigger);

    return ft;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:66,代码来源:QuartzScheduler.java

示例2: rescheduleJob

import org.quartz.spi.OperableTrigger; //导入方法依赖的package包/类
/**
 * <p>
 * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
 * given name, and store the new given one - which must be associated
 * with the same job.
 * </p>
 * @param newTrigger
 *          The new <code>Trigger</code> to be stored.
 * 
 * @return <code>null</code> if a <code>Trigger</code> with the given
 *         name & group was not found and removed from the store, otherwise
 *         the first fire time of the newly scheduled trigger.
 */
public Date rescheduleJob(TriggerKey triggerKey,
        Trigger newTrigger) throws SchedulerException {
    validateState();

    if (triggerKey == null) {
        throw new IllegalArgumentException("triggerKey cannot be null");
    }
    if (newTrigger == null) {
        throw new IllegalArgumentException("newTrigger cannot be null");
    }

    OperableTrigger trig = (OperableTrigger)newTrigger;
    Trigger oldTrigger = getTrigger(triggerKey);
    if (oldTrigger == null) {
        return null;
    } else {
        trig.setJobKey(oldTrigger.getJobKey());
    }
    trig.validate();

    Calendar cal = null;
    if (newTrigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(
                newTrigger.getCalendarName());
    }
    Date ft = trig.computeFirstFireTime(cal);

    if (ft == null) {
        throw new SchedulerException(
                "Based on configured schedule, the given trigger will never fire.");
    }
    
    if (resources.getJobStore().replaceTrigger(triggerKey, trig)) {
        notifySchedulerThread(newTrigger.getNextFireTime().getTime());
        notifySchedulerListenersUnscheduled(triggerKey);
        notifySchedulerListenersSchduled(newTrigger);
    } else {
        return null;
    }

    return ft;
    
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:57,代码来源:QuartzScheduler.java


注:本文中的org.quartz.spi.OperableTrigger.setJobKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。