Search in sources :

Example 46 with JobExecutionContext

use of org.quartz.JobExecutionContext in project weicoder by wdcode.

the class ExecutingJobsManager method interrupt.

/**
 * Interrupt the identified InterruptableJob executing in this Scheduler instance.
 *
 * <p>
 * This method is not cluster aware.  That is, it will only interrupt
 * instances of the identified InterruptableJob currently executing in this
 * Scheduler instance, not across the entire cluster.
 * </p>
 *
 * @see org.quartz.core.RemotableQuartzScheduler#interrupt(JobKey)
 */
public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobException {
    List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
    Job job = null;
    for (JobExecutionContext jec : jobs) {
        if (jec.getFireInstanceId().equals(fireInstanceId)) {
            job = jec.getJobInstance();
            if (job instanceof InterruptableJob) {
                ((InterruptableJob) job).interrupt();
                return true;
            } else {
                throw new UnableToInterruptJobException("Job " + jec.getJobDetail().getKey() + " can not be interrupted, since it does not implement " + InterruptableJob.class.getName());
            }
        }
    }
    return false;
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) InterruptableJob(org.quartz.InterruptableJob) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job) InterruptableJob(org.quartz.InterruptableJob)

Example 47 with JobExecutionContext

use of org.quartz.JobExecutionContext in project weicoder by wdcode.

the class JobExecutionContextSupport method toTabularData.

/**
 * @return array of region statistics
 */
public static TabularData toTabularData(final List<JobExecutionContext> executingJobs) throws SchedulerException {
    List<CompositeData> list = new ArrayList<CompositeData>();
    for (JobExecutionContext executingJob : executingJobs) {
        list.add(toCompositeData(executingJob));
    }
    TabularData td = new TabularDataSupport(TABULAR_TYPE);
    td.putAll(list.toArray(new CompositeData[list.size()]));
    return td;
}
Also used : TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) JobExecutionContext(org.quartz.JobExecutionContext) TabularData(javax.management.openmbean.TabularData)

Example 48 with JobExecutionContext

use of org.quartz.JobExecutionContext in project smarthome by eclipse.

the class MockScheduler method run.

/**
 * "Run" all of the jobs in the scheduler.
 *
 * NB this is a mock class. We ignore the time that the jobs are
 * actually scheduled for, and just run them all.
 *
 * @throws JobExecutionException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
public void run() throws JobExecutionException, InstantiationException, IllegalAccessException {
    for (Entry<Trigger, JobExecutionContext> entry : jobs.entrySet()) {
        JobExecutionContext context = entry.getValue();
        try {
            currentlyExecutingJobs.add(context);
            Job job = context.getJobDetail().getJobClass().newInstance();
            job.execute(context);
        } finally {
            currentlyExecutingJobs.remove(context);
            jobs.remove(entry.getKey());
            Trigger newTrigger = rescheduledJobs.remove(context.getTrigger().getKey());
            if (newTrigger != null) {
                jobs.put(newTrigger, context);
            }
        }
    }
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job)

Aggregations

JobExecutionContext (org.quartz.JobExecutionContext)48 Test (org.junit.Test)20 JobDetail (org.quartz.JobDetail)20 JobDataMap (org.quartz.JobDataMap)13 Set (java.util.Set)10 JobExecutionException (org.quartz.JobExecutionException)10 List (java.util.List)8 SchedulerException (org.quartz.SchedulerException)8 VirtConsumerMap (org.candlepin.model.VirtConsumerMap)7 Job (org.quartz.Job)7 ArrayList (java.util.ArrayList)5 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)5 Consumer (org.candlepin.model.Consumer)4 InterruptableJob (org.quartz.InterruptableJob)4 Scheduler (org.quartz.Scheduler)4 Date (java.util.Date)3 Map (java.util.Map)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2