use of org.quartz.JobExecutionContext in project kernel by exoplatform.
the class JobSchedulerServiceImpl method stop.
public void stop() {
try {
List<JobExecutionContext> jobs = getAllExcutingJobs();
for (JobExecutionContext ctx : jobs) {
Job job = ctx.getJobInstance();
if (job instanceof InterruptableJob) {
((InterruptableJob) job).interrupt();
}
}
scheduler_.shutdown(true);
} catch (Exception ex) {
LOG.warn("Could not interrupt all the current jobs properly", ex);
}
}
use of org.quartz.JobExecutionContext in project ddf by codice.
the class CommandJobTest method createMockJobExecutionContext.
private JobExecutionContext createMockJobExecutionContext(String command) {
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(CommandJob.COMMAND_KEY, command);
JobExecutionContext context = mock(JobExecutionContext.class);
when(context.getMergedJobDataMap()).thenReturn(jobDataMap);
return context;
}
use of org.quartz.JobExecutionContext in project ddf by codice.
the class CommandJobTest method testNullMergedJobDataMap.
/**
* Tests that there is no exception when the {@link JobDataMap} of the {@link JobExecutionContext}
* is null
*/
@Test
public void testNullMergedJobDataMap() {
// given
CommandJob commandJob = new CommandJob(new Security());
JobExecutionContext jobExecutionContext = mock(JobExecutionContext.class);
when(jobExecutionContext.getMergedJobDataMap()).thenReturn(null);
// when
commandJob.execute(jobExecutionContext);
}
use of org.quartz.JobExecutionContext in project jaffa-framework by jaffa-projects.
the class TransactionInvokerJob method execute.
/**
* Called by the <code>{@link org.quartz.Scheduler}</code> when a
* <code>{@link org.quartz.Trigger}</code> fires that is associated with
* the <code>Job</code>.
*
* @param context The Quartz JobExecutionContext structure used to retrieve job specific information
* @throws JobExecutionException if there is an exception while executing the job.
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
String scheduledTaskId = null;
String userId = null;
Object businessObject = null;
UserContextWrapper ucw = null;
try {
List<JobExecutionContext> jobs = context.getScheduler().getCurrentlyExecutingJobs();
if (log.isDebugEnabled())
log.debug("Job Size:- " + jobs.size());
if (log.isDebugEnabled())
log.debug("Starting Checking Scheduled Tasks");
for (JobExecutionContext job : jobs) {
if (log.isDebugEnabled()) {
log.debug("Job Trigger: " + job.getTrigger());
log.debug("Context Trigger: " + context.getTrigger());
}
if (job.getTrigger().equals(context.getTrigger()) && !job.getJobInstance().equals(this)) {
if (log.isDebugEnabled())
log.debug("There's another instance running, so leaving" + this);
return;
}
}
// Obtain the Task from the Job details
ScheduledTask task = QuartzSchedulerHelper.jobDataMapToTask(context.getJobDetail().getJobDataMap());
if (log.isDebugEnabled())
log.debug("Executing " + task);
scheduledTaskId = task.getScheduledTaskId();
userId = task.getRunAs();
businessObject = task.getBusinessObject();
// Switch the thread to use the context the "RunAs" is set to, so this propergates when creating the JaffaTransaction/JMS records to process
if (log.isDebugEnabled())
log.debug("Set up use context. RunAs = " + userId);
ucw = UserContextWrapperFactory.instance(userId);
// Sets Log4J's MDC to enable BusinessEventLogging
MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, scheduledTaskId);
MDC.put(BusinessEventLogMeta.LOGGED_BY, userId);
// Set up some Thread Level variables for the Jaffa Transaction. This will help distinguish between a Schedule invoke transaction and any others
ContextManagerFactory.instance().setProperty(CONTEXT_SCHEDULED_TASK_ID, scheduledTaskId);
// Send a Jaffa Transaction message
if (log.isInfoEnabled())
log.info(MessageHelper.findMessage("label.Jaffa.Scheduler.JaffaTransactionInvokerJob.start", new Object[] { businessObject, userId, scheduledTaskId }));
UOWHelper.addMessage(businessObject);
if (log.isInfoEnabled())
log.info(MessageHelper.findMessage("label.Jaffa.Scheduler.JaffaTransactionInvokerJob.success", new Object[] { businessObject, userId, scheduledTaskId }));
} catch (Exception e) {
log.error(MessageHelper.findMessage("error.Jaffa.Scheduler.JaffaTransactionInvokerJob.error", new Object[] { businessObject, userId, scheduledTaskId }), e);
throw new JobExecutionException(e);
} finally {
// Unset the Logging context
MDC.remove(BusinessEventLogMeta.SCHEDULED_TASK_ID);
MDC.remove(BusinessEventLogMeta.LOGGED_BY);
// Clear context for this user
if (ucw != null) {
if (log.isDebugEnabled())
log.debug("Unset user context");
ucw.unsetContext();
}
}
}
use of org.quartz.JobExecutionContext in project wso2-synapse by wso2.
the class QuartzTaskManager method isTaskRunning.
@Override
public boolean isTaskRunning(Object taskKey) {
if (!(taskKey instanceof JobKey)) {
return false;
}
try {
List<JobExecutionContext> currentJobs;
synchronized (lock) {
currentJobs = this.scheduler.getCurrentlyExecutingJobs();
}
JobKey currentJobKey;
for (JobExecutionContext jobCtx : currentJobs) {
currentJobKey = jobCtx.getJobDetail().getKey();
if (currentJobKey.compareTo((JobKey) taskKey) == 0) {
logger.warn("the job is already running");
return true;
}
}
} catch (SchedulerException e) {
return false;
}
return false;
}
Aggregations