org.quartz.Trigger#validate ( )源码实例Demo

下面列出了org.quartz.Trigger#validate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AsuraFramework   文件: 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(SchedulingContext ctxt, Trigger trigger)
    throws SchedulerException {
    validateState();

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

    trigger.validate();

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

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

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

    return ft;
}
 
源代码2 项目: AsuraFramework   文件: QuartzScheduler.java
/**
 * <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 triggerName
 *          The name of the <code>Trigger</code> to be removed.
 * @param groupName
 *          The group name of the <code>Trigger</code> to be removed.
 * @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(SchedulingContext ctxt, String triggerName,
        String groupName, Trigger newTrigger) throws SchedulerException {
    validateState();

    if(groupName == null) {
        groupName = Scheduler.DEFAULT_GROUP;
    }

    newTrigger.validate();

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

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

    return ft;
    
}
 
源代码3 项目: AsuraFramework   文件: QuartzScheduler.java
/**
 * <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(SchedulingContext ctxt, JobDetail jobDetail,
        Trigger trigger) throws SchedulerException {
    validateState();

    if (jobDetail == null) {
        throw new SchedulerException("JobDetail cannot be null",
                SchedulerException.ERR_CLIENT_ERROR);
    }
    
    if (trigger == null) {
        throw new SchedulerException("Trigger cannot be null",
                SchedulerException.ERR_CLIENT_ERROR);
    }
    
    jobDetail.validate();

    if (trigger.getJobName() == null) {
        trigger.setJobName(jobDetail.getName());
        trigger.setJobGroup(jobDetail.getGroup());
    } else if (trigger.getJobName() != null
            && !trigger.getJobName().equals(jobDetail.getName())) {
        throw new SchedulerException(
            "Trigger does not reference given job!",
            SchedulerException.ERR_CLIENT_ERROR);
    } else if (trigger.getJobGroup() != null
            && !trigger.getJobGroup().equals(jobDetail.getGroup())) {
        throw new SchedulerException(
            "Trigger does not reference given job!",
            SchedulerException.ERR_CLIENT_ERROR);
    }

    trigger.validate();

    Calendar cal = null;
    if (trigger.getCalendarName() != null) {
        cal = resources.getJobStore().retrieveCalendar(ctxt,
                trigger.getCalendarName());
    }
    Date ft = trigger.computeFirstFireTime(cal);

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

    resources.getJobStore().storeJobAndTrigger(ctxt, jobDetail, trigger);
    notifySchedulerListenersJobAdded(jobDetail);
    notifySchedulerThread(trigger.getNextFireTime().getTime());
    notifySchedulerListenersSchduled(trigger);

    return ft;
}