Java Code Examples for org.quartz.JobExecutionContext#getJobInstance()

The following examples show how to use org.quartz.JobExecutionContext#getJobInstance() . 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: QuartzScheduler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: FoxbpmJobExecutionContext.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
public FoxbpmJobExecutionContext(JobExecutionContext jobExecutionContext) {
	JobDataMap jobDataMap = jobExecutionContext.getJobDetail()
			.getJobDataMap();
	scheduleJob = jobExecutionContext.getJobInstance();
	this.tokenId = jobDataMap.getString(TOKEN_ID);
	this.processInstanceId = jobDataMap.getString(PROCESS_INSTANCE_ID);
	this.nodeId = jobDataMap.getString(NODE_ID);
	this.processKey = jobDataMap.getString(PROCESS_DEFINITION_KEY);
	this.processId = jobDataMap.getString(PROCESS_DEFINITION_ID);
	this.processName = jobDataMap.getString(PROCESS_DEFINITION_NAME);
	this.bizKey = jobDataMap.getString(BUSINESS_KEY);
	this.jobType = jobDataMap.getString("jobType");
	this.connectorId = jobDataMap.getString(CONNECTOR_ID);
	this.connectorInstanceId = jobDataMap.getString(CONNECTOR_INSTANCE_ID);
	this.connectorInstanceName = jobDataMap
			.getString(CONNECTOR_INSTANCE_NAME);
	this.eventType = jobDataMap.getString(EVENT_TYPE);
	this.eventName = jobDataMap.getString(EVENT_NAME);
	this.taskId = jobDataMap.getString(TASK_ID);

}
 
Example 3
Source File: JobListener.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
 */
@Override
public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
    if (jobExecutionContext.getJobInstance() instanceof Job) {
        schedulerService.initializeJob(jobExecutionContext.getJobDetail().getName(), (Job) jobExecutionContext.getJobInstance());
        initializeLogging(jobExecutionContext);
        // We only want to auto-cancel executions if they are part of a master scheduling job
        // Otherwise, this is a standalone job and should fire, regardless of prior status
        if ( jobExecutionContext.getMergedJobDataMap().containsKey(Job.MASTER_JOB_NAME) ) {
            if (schedulerService.shouldNotRun(jobExecutionContext.getJobDetail())) {
                ((Job) jobExecutionContext.getJobInstance()).setNotRunnable(true);
            }
        } else {
            ((Job) jobExecutionContext.getJobInstance()).setNotRunnable(false);
        }
    }
}
 
Example 4
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Interrupt all instances of 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(JobKey jobKey) throws UnableToInterruptJobException {

    List<JobExecutionContext> jobs = getCurrentlyExecutingJobs();
    
    JobDetail jobDetail = null;
    Job job = null;
    
    boolean interrupted = false;
    
    for(JobExecutionContext jec : jobs) {
        jobDetail = jec.getJobDetail();
        if (jobKey.equals(jobDetail.getKey())) {
            job = jec.getJobInstance();
            if (job instanceof InterruptableJob) {
                ((InterruptableJob)job).interrupt();
                interrupted = true;
            } else {
                throw new UnableToInterruptJobException(
                        "Job " + jobDetail.getKey() +
                        " can not be interrupted, since it does not implement " +                        
                        InterruptableJob.class.getName());
            }
        }                        
    }
    
    return interrupted;
}
 
Example 5
Source File: JobListener.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
 */
@Override
public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException jobExecutionException) {
    if (jobExecutionContext.getJobInstance() instanceof Job) {
        try {
            if (!((Job) jobExecutionContext.getJobInstance()).isNotRunnable()) {
                notify(jobExecutionContext, schedulerService.getStatus(jobExecutionContext.getJobDetail()));
            }
        } finally {
            completeLogging(jobExecutionContext);
        }
    }
}
 
Example 6
Source File: JobListener.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
 */
@Override
public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
    if (jobExecutionContext.getJobInstance() instanceof Job) {
        throw new UnsupportedOperationException("JobListener does not implement jobExecutionVetoed(JobExecutionContext jobExecutionContext)");
    }
}
 
Example 7
Source File: MessageServiceExecutorJobListener.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
    * This overridden method ...
    * 
    * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
    */
   public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
if (context.getJobInstance() instanceof MessageServiceExecutorJob && exception != null) {
    PersistedMessageBO message = (PersistedMessageBO)context.getJobDetail().getJobDataMap().get(MessageServiceExecutorJob.MESSAGE_KEY);
    message.setQueueStatus(KSBConstants.ROUTE_QUEUE_EXCEPTION);
    message = KSBServiceLocator.getMessageQueueService().save(message);
}

   }