Search in sources :

Example 1 with Trigger

use of org.apache.openejb.quartz.Trigger in project tomee by apache.

the class EjbTimerServiceImpl method schedule.

/**
 * Called from TimerData and start when a timer should be scheduled with the java.util.Timer.
 *
 * @param timerData the timer to schedule
 */
public void schedule(final TimerData timerData) throws TimerStoreException {
    start();
    if (scheduler == null) {
        throw new TimerStoreException("Scheduler is not configured properly");
    }
    timerData.setScheduler(scheduler);
    final Trigger trigger = timerData.getTrigger();
    if (null == trigger) {
        try {
            if (!scheduler.isShutdown()) {
                log.warning("Failed to schedule: " + timerData.getInfo());
            }
        } catch (final SchedulerException e) {
        // Ignore
        }
    }
    final AbstractTrigger<?> atrigger;
    if (trigger instanceof AbstractTrigger) {
        // is the case
        atrigger = (AbstractTrigger<?>) trigger;
        atrigger.setJobName(OPENEJB_TIMEOUT_JOB_NAME);
        atrigger.setJobGroup(OPENEJB_TIMEOUT_JOB_GROUP_NAME);
    } else {
        throw new OpenEJBRuntimeException("the trigger was not an AbstractTrigger - Should not be possible: " + trigger);
    }
    final JobDataMap triggerDataMap = trigger.getJobDataMap();
    triggerDataMap.put(EjbTimeoutJob.EJB_TIMERS_SERVICE, this);
    triggerDataMap.put(EjbTimeoutJob.TIMER_DATA, timerData);
    try {
        final TriggerKey triggerKey = new TriggerKey(atrigger.getName(), atrigger.getGroup());
        if (!scheduler.checkExists(triggerKey)) {
            scheduler.scheduleJob(trigger);
        } else if (Trigger.TriggerState.PAUSED.equals(scheduler.getTriggerState(triggerKey))) {
            // redeployment
            // more consistent in the semantic than a resume but resume would maybe be more relevant here
            scheduler.unscheduleJob(triggerKey);
            scheduler.scheduleJob(trigger);
        }
    } catch (final Exception e) {
        // TODO Any other actions we could do ?
        log.error("Could not schedule timer " + timerData, e);
    }
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TriggerKey(org.apache.openejb.quartz.TriggerKey) JobDataMap(org.apache.openejb.quartz.JobDataMap) Trigger(org.apache.openejb.quartz.Trigger) AbstractTrigger(org.apache.openejb.quartz.impl.triggers.AbstractTrigger) SchedulerException(org.apache.openejb.quartz.SchedulerException) AbstractTrigger(org.apache.openejb.quartz.impl.triggers.AbstractTrigger) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) SchedulerException(org.apache.openejb.quartz.SchedulerException) ApplicationException(org.apache.openejb.ApplicationException) IOException(java.io.IOException) SystemException(javax.transaction.SystemException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 2 with Trigger

use of org.apache.openejb.quartz.Trigger in project tomee by apache.

the class EjbTimerServiceImpl method cleanTimerData.

private void cleanTimerData() {
    if (timerStore == null || scheduler == null || deployment == null) {
        return;
    }
    final Collection<TimerData> timerDatas = timerStore.getTimers(deployment.getDeploymentID().toString());
    if (timerDatas == null) {
        return;
    }
    for (final TimerData data : timerDatas) {
        final Trigger trigger = data.getTrigger();
        if (trigger == null) {
            continue;
        }
        final TriggerKey key = trigger.getKey();
        try {
            data.stop();
        } catch (final EJBException ignored) {
            log.warning("An error occured deleting trigger '" + key + "' on bean " + deployment.getDeploymentID());
        }
    }
}
Also used : TriggerKey(org.apache.openejb.quartz.TriggerKey) Trigger(org.apache.openejb.quartz.Trigger) AbstractTrigger(org.apache.openejb.quartz.impl.triggers.AbstractTrigger) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Aggregations

EJBException (javax.ejb.EJBException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 Trigger (org.apache.openejb.quartz.Trigger)2 TriggerKey (org.apache.openejb.quartz.TriggerKey)2 AbstractTrigger (org.apache.openejb.quartz.impl.triggers.AbstractTrigger)2 IOException (java.io.IOException)1 SystemException (javax.transaction.SystemException)1 ApplicationException (org.apache.openejb.ApplicationException)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1 JobDataMap (org.apache.openejb.quartz.JobDataMap)1 SchedulerException (org.apache.openejb.quartz.SchedulerException)1