Search in sources :

Example 1 with SchedulerException

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

the class QuartzResourceAdapter method endpointDeactivation.

@Override
public void endpointDeactivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) {
    final Scheduler s = scheduler.get();
    if (null == s) {
        throw new IllegalStateException("Quartz Scheduler is not available");
    }
    JobSpec spec = null;
    try {
        spec = (JobSpec) activationSpec;
        s.deleteJob(spec.jobKey());
    } catch (final SchedulerException e) {
        throw new IllegalStateException("Failed to delete job", e);
    } finally {
        if (null != spec) {
            spec.getEndpoint().release();
        }
    }
}
Also used : SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler)

Example 2 with SchedulerException

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

the class QuartzResourceAdapter method endpointActivation.

@Override
public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) throws ResourceException {
    final Scheduler s = scheduler.get();
    if (null == s) {
        throw new ResourceException("Quartz Scheduler is not available");
    }
    try {
        final JobSpec spec = (JobSpec) activationSpec;
        final MessageEndpoint endpoint = messageEndpointFactory.createEndpoint(null);
        spec.setEndpoint(endpoint);
        final Job job = (Job) endpoint;
        final JobDataMap jobDataMap = spec.getDetail().getJobDataMap();
        jobDataMap.put(Data.class.getName(), new Data(job));
        s.scheduleJob(spec.getDetail(), spec.getTrigger());
    } catch (final SchedulerException e) {
        throw new ResourceException("Failed to schedule job", e);
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) JobDataMap(org.apache.openejb.quartz.JobDataMap) SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler) ResourceException(javax.resource.ResourceException) Job(org.apache.openejb.quartz.Job)

Example 3 with SchedulerException

use of org.apache.openejb.quartz.SchedulerException 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 4 with SchedulerException

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

the class TimerData method cancel.

public void cancel() {
    if (stopped) {
        return;
    }
    timerService.cancelled(TimerData.this);
    if (trigger != null) {
        try {
            final Scheduler s = timerService.getScheduler();
            if (!s.isShutdown()) {
                s.unscheduleJob(trigger.getKey());
            }
        } catch (final SchedulerException e) {
            throw new EJBException("fail to cancel the timer", e);
        }
    }
    cancelled = true;
    try {
        registerTimerDataSynchronization();
    } catch (final TimerStoreException e) {
        throw new EJBException("Failed to register timer data synchronization on cancel", e);
    }
}
Also used : SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler) EJBException(javax.ejb.EJBException)

Example 5 with SchedulerException

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

the class TimerData method stop.

public void stop() {
    if (trigger != null) {
        try {
            final Scheduler s = timerService.getScheduler();
            if (!s.isShutdown()) {
                if (!isPersistent()) {
                    s.unscheduleJob(trigger.getKey());
                } else {
                    s.pauseTrigger(trigger.getKey());
                }
            }
        } catch (final SchedulerException e) {
            throw new EJBException("fail to cancel the timer", e);
        }
    }
    cancelled = true;
    stopped = true;
}
Also used : SchedulerException(org.apache.openejb.quartz.SchedulerException) Scheduler(org.apache.openejb.quartz.Scheduler) EJBException(javax.ejb.EJBException)

Aggregations

SchedulerException (org.apache.openejb.quartz.SchedulerException)8 Scheduler (org.apache.openejb.quartz.Scheduler)5 EJBException (javax.ejb.EJBException)4 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 IOException (java.io.IOException)2 MessageEndpoint (javax.resource.spi.endpoint.MessageEndpoint)2 SystemException (javax.transaction.SystemException)2 ApplicationException (org.apache.openejb.ApplicationException)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 JobDataMap (org.apache.openejb.quartz.JobDataMap)2 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ResourceException (javax.resource.ResourceException)1 InvalidPropertyException (javax.resource.spi.InvalidPropertyException)1 SystemInstance (org.apache.openejb.loader.SystemInstance)1 CronScheduleBuilder (org.apache.openejb.quartz.CronScheduleBuilder)1 Job (org.apache.openejb.quartz.Job)1 JobDetail (org.apache.openejb.quartz.JobDetail)1 Trigger (org.apache.openejb.quartz.Trigger)1