Java Code Examples for org.quartz.Trigger#getCalendarName()

The following examples show how to use org.quartz.Trigger#getCalendarName() . 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: 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 2
Source File: RAMJobStore.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <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(SchedulingContext ctxt, String calName)
    throws JobPersistenceException {
    int numRefs = 0;

    synchronized (lock) {
        Iterator itr = triggers.iterator();
        while (itr.hasNext()) {
            Trigger trigg = ((TriggerWrapper) itr.next()).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);
}
 
Example 3
Source File: JobStoreSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
private void doUpdateOfMisfiredTrigger(Connection conn, SchedulingContext ctxt, Trigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
    Calendar cal = null;
    if (trig.getCalendarName() != null) {
        cal = retrieveCalendar(conn, ctxt, trig.getCalendarName());
    }

    schedSignaler.notifyTriggerListenersMisfired(trig);

    trig.updateAfterMisfire(cal);

    if (trig.getNextFireTime() == null) {
        storeTrigger(conn, ctxt, trig,
            null, true, STATE_COMPLETE, forceState, recovering);
    } else {
        storeTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete,
                forceState, false);
    }
}
 
Example 4
Source File: TriggerSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
public static CompositeData toCompositeData(Trigger trigger) {
	try {
		return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
				new Object[] {
						trigger.getName(),
						trigger.getGroup(),
						trigger.getJobName(),
						trigger.getJobGroup(),
						trigger.getDescription(),
						JobDataMapSupport.toTabularData(trigger
								.getJobDataMap()), trigger.isVolatile(),
						trigger.getCalendarName(),
						trigger.getFireInstanceId(),
						trigger.getMisfireInstruction(),
						trigger.getPriority(), trigger.getStartTime(),
						trigger.getEndTime(), trigger.getNextFireTime(),
						trigger.getPreviousFireTime(),
						trigger.getFinalFireTime() });
	} catch (OpenDataException e) {
		throw new RuntimeException(e);
	}
}
 
Example 5
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 6
Source File: SchedulerServiceSupplier.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Builds the triggers list xml string.
 * 
 * @param triggers the triggers
 * 
 * @return the string
 * 
 * @throws SourceBeanException the source bean exception
 */
public  String buildTriggersListXmlString(Trigger[] triggers) throws SourceBeanException {
	StringBuffer buffer = new StringBuffer("<ROWS>");
	if (triggers != null && triggers.length > 0) {
		for (int i = 0; i < triggers.length; i++) {
			Trigger trigger = triggers[i];
			if(trigger.getName().startsWith("schedule_uuid_")) {
				continue;
			}
			buffer.append("<ROW ");
			String triggerName = trigger.getName();
			String triggerGroup = trigger.getGroup();
			String triggerDescription = trigger.getDescription();
			String triggerCalendarName = trigger.getCalendarName();
			Date triggerStartTime = trigger.getStartTime();
			String triggerStartTimeStr = triggerStartTime != null ? triggerStartTime.toString(): "";
			Date triggerEndTime = trigger.getEndTime();
			String triggerEndTimeStr = triggerEndTime != null ? triggerEndTime.toString(): "";
			buffer.append(" triggerName=\"" + (triggerName != null ? triggerName : "") + "\"");
			buffer.append(" triggerGroup=\"" + (triggerGroup != null ? triggerGroup : "") + "\"");
			buffer.append(" triggerDescription=\"" + (triggerDescription != null ? triggerDescription : "") + "\"");
			buffer.append(" triggerCalendarName=\"" + (triggerCalendarName != null ? triggerCalendarName : "") + "\"");
			buffer.append(" triggerStartTime=\"" + triggerStartTimeStr + "\"");
			buffer.append(" triggerEndTime=\"" + triggerEndTimeStr + "\"");
			buffer.append(" />");
		}
	}
	buffer.append("</ROWS>");
	return buffer.toString();
}
 
Example 7
Source File: QuartzScheduler.java    From AsuraFramework with Apache License 2.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(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;
}
 
Example 8
Source File: QuartzScheduler.java    From AsuraFramework with Apache License 2.0 5 votes vote down vote up
/**
 * <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;
    
}
 
Example 9
Source File: SchedulerAdapter.java    From iaf with Apache License 2.0 5 votes vote down vote up
public XmlBuilder triggerToXmlBuilder(Trigger trigger) {
    XmlBuilder xbRoot = new XmlBuilder("triggerDetail");

    TriggerKey triggerKey = trigger.getKey();
    xbRoot.addAttribute("fullName", triggerKey.getGroup() + "." + triggerKey.getName());
    xbRoot.addAttribute("triggerName", triggerKey.getName());
    xbRoot.addAttribute("triggerGroup", triggerKey.getGroup());
    String cn = trigger.getCalendarName();

    xbRoot.addAttribute("calendarName", (cn == null ? "none" : cn));

    xbRoot.addAttribute("endTime", convertDate(trigger.getEndTime()));
    xbRoot.addAttribute("finalFireTime", convertDate(trigger.getFinalFireTime()));
    xbRoot.addAttribute("previousFireTime", convertDate(trigger.getPreviousFireTime()));
    xbRoot.addAttribute("nextFireTime", convertDate(trigger.getNextFireTime()));
    xbRoot.addAttribute("startTime", convertDate(trigger.getStartTime()));

    xbRoot.addAttribute("misfireInstruction", Integer.toString(trigger.getMisfireInstruction()));
    if (trigger instanceof CronTrigger) {
        xbRoot.addAttribute("triggerType", "cron");
        xbRoot.addAttribute("cronExpression", ((CronTrigger)trigger).getCronExpression());
    } else if (trigger instanceof SimpleTrigger) {
        xbRoot.addAttribute("triggerType", "simple");
        xbRoot.addAttribute("repeatInterval", ((SimpleTrigger)trigger).getRepeatInterval());
    } else {
        xbRoot.addAttribute("triggerType", "unknown");
    }

    return xbRoot;
}
 
Example 10
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <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;
}
 
Example 11
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * <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;
    
}
 
Example 12
Source File: QuartzScheduler.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
/**
 * <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;
}