use of org.quartz.JobExecutionContext in project weicoder by wdcode.
the class ExecutingJobsManager method interrupt.
/**
* 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;
}
use of org.quartz.JobExecutionContext in project midpoint by Evolveum.
the class TestQuartzTaskManagerContract method test105LightweightSubtasksSuspension.
@Test(enabled = true)
public void test105LightweightSubtasksSuspension() throws Exception {
final String test = "105LightweightSubtasksSuspension";
final OperationResult result = createResult(test);
addObjectFromFile(taskFilename(test));
Task task = taskManager.getTask(taskOid(test), result);
System.out.println("After setup: " + task.debugDump());
waitFor("Waiting for task manager to start the task", new Checker() {
public boolean check() throws ObjectNotFoundException, SchemaException {
Task task = taskManager.getTask(taskOid(test), result);
IntegrationTestTools.display("Task while waiting for task manager to execute the task", task);
return task.getLastRunStartTimestamp() != null && task.getLastRunStartTimestamp() != 0L;
}
@Override
public void timeout() {
}
}, 15000, 500);
task.refresh(result);
System.out.println("After refresh (task was started; and it should run now): " + task.debugDump());
AssertJUnit.assertEquals(TaskExecutionStatus.RUNNABLE, task.getExecutionStatus());
// check the thread
List<JobExecutionContext> jobExecutionContexts = taskManager.getExecutionManager().getQuartzScheduler().getCurrentlyExecutingJobs();
JobExecutionContext found = null;
for (JobExecutionContext jobExecutionContext : jobExecutionContexts) {
if (task.getOid().equals(jobExecutionContext.getJobDetail().getKey().getName())) {
found = jobExecutionContext;
break;
}
}
assertNotNull("Job for the task was not found", found);
JobExecutor executor = (JobExecutor) found.getJobInstance();
assertNotNull("No job executor", executor);
Thread thread = executor.getExecutingThread();
assertNotNull("No executing thread", thread);
// now let us suspend it - the handler should stop, as well as the subtasks
boolean stopped = taskManager.suspendTask(task, 10000L, result);
task.refresh(result);
AssertJUnit.assertTrue("Task is not stopped", stopped);
AssertJUnit.assertEquals("Task is not suspended", TaskExecutionStatus.SUSPENDED, task.getExecutionStatus());
Collection<? extends Task> subtasks = parallelTaskHandler.getLastTaskExecuted().getLightweightAsynchronousSubtasks();
assertEquals("Wrong number of subtasks", MockParallelTaskHandler.NUM_SUBTASKS, subtasks.size());
for (Task subtask : subtasks) {
assertEquals("Wrong subtask state", TaskExecutionStatus.CLOSED, subtask.getExecutionStatus());
MockParallelTaskHandler.MyLightweightTaskHandler handler = (MockParallelTaskHandler.MyLightweightTaskHandler) subtask.getLightweightTaskHandler();
assertTrue("Handler has not run", handler.hasRun());
assertTrue("Handler has not exited", handler.hasExited());
}
}
use of org.quartz.JobExecutionContext in project ddf by codice.
the class CommandJobTest method getJobExecutionContext.
private JobExecutionContext getJobExecutionContext(String command) {
JobExecutionContext context = mock(JobExecutionContext.class);
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(CommandJob.COMMAND_KEY, command);
when(context.getMergedJobDataMap()).thenReturn(jobDataMap);
return context;
}
use of org.quartz.JobExecutionContext in project OpenOLAT by OpenOLAT.
the class NotificationsAdminWebService method getJobStatus.
private String getJobStatus() {
try {
Scheduler scheduler = CoreSpringFactory.getImpl(Scheduler.class);
List<JobExecutionContext> jobs = scheduler.getCurrentlyExecutingJobs();
for (JobExecutionContext job : jobs) {
if ("org.olat.notifications.job.enabled".equals(job.getJobDetail().getKey().getName())) {
return "running";
}
}
return "stopped";
} catch (SchedulerException e) {
log.error("", e);
return "error";
}
}
use of org.quartz.JobExecutionContext in project syncope by apache.
the class SetUMembershipsJob method execute.
@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
try {
AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY), () -> {
@SuppressWarnings("unchecked") Map<String, Set<String>> memberships = (Map<String, Set<String>>) context.getMergedJobDataMap().get(MEMBERSHIPS_KEY);
LOG.debug("About to set memberships (User -> Groups) {}", memberships);
memberships.entrySet().stream().map(membership -> {
UserPatch userPatch = new UserPatch();
userPatch.setKey(membership.getKey());
membership.getValue().forEach(groupKey -> {
userPatch.getMemberships().add(new MembershipPatch.Builder().operation(PatchOperation.ADD_REPLACE).group(groupKey).build());
});
return userPatch;
}).filter(userPatch -> (!userPatch.isEmpty())).map((userPatch) -> {
LOG.debug("About to update User {}", userPatch.getKey());
return userPatch;
}).forEachOrdered((userPatch) -> {
userProvisioningManager.update(userPatch, true);
});
return null;
});
} catch (RuntimeException e) {
LOG.error("While setting memberships", e);
throw new JobExecutionException("While executing memberships", e);
}
}
Aggregations