use of org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext in project jbpm by kiegroup.
the class ThreadPoolSchedulerService method scheduleJob.
@Override
public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
Date date = trigger.hasNextFireTime();
if (date != null) {
String jobname = null;
if (ctx instanceof ProcessJobContext) {
ProcessJobContext processCtx = (ProcessJobContext) ctx;
jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId();
if (processCtx instanceof StartProcessJobContext) {
jobname = "StartProcess-" + ((StartProcessJobContext) processCtx).getProcessId() + "-" + processCtx.getTimer().getId();
}
if (activeTimer.containsKey(jobname)) {
return activeTimer.get(jobname);
}
}
GlobalJDKJobHandle jobHandle = new GlobalJDKJobHandle(idCounter.getAndIncrement());
TimerJobInstance jobInstance = globalTimerService.getTimerJobFactoryManager().createTimerJobInstance(job, ctx, trigger, jobHandle, (InternalSchedulerService) globalTimerService);
jobHandle.setTimerJobInstance((TimerJobInstance) jobInstance);
interceptor.internalSchedule((TimerJobInstance) jobInstance);
if (jobname != null) {
activeTimer.put(jobname, jobHandle);
}
return jobHandle;
} else {
return null;
}
}
use of org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext in project jbpm by kiegroup.
the class EjbSchedulerService method getJobName.
private String getJobName(JobContext ctx, Long id) {
String jobname = null;
if (ctx instanceof ProcessJobContext) {
ProcessJobContext processCtx = (ProcessJobContext) ctx;
jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId();
if (processCtx instanceof StartProcessJobContext) {
jobname = "StartProcess-" + ((StartProcessJobContext) processCtx).getProcessId() + "-" + processCtx.getTimer().getId();
}
} else if (ctx instanceof NamedJobContext) {
jobname = ((NamedJobContext) ctx).getJobName();
} else {
jobname = "Timer-" + ctx.getClass().getSimpleName() + "-" + id;
}
return jobname;
}
use of org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext in project jbpm by kiegroup.
the class QuartzSchedulerService method scheduleJob.
@Override
public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
Long id = idCounter.getAndIncrement();
String jobname = null;
String groupName = "jbpm";
if (ctx instanceof ProcessJobContext) {
ProcessJobContext processCtx = (ProcessJobContext) ctx;
jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId();
if (processCtx instanceof StartProcessJobContext) {
jobname = "StartProcess-" + ((StartProcessJobContext) processCtx).getProcessId() + "-" + processCtx.getTimer().getId();
}
String deploymentId = (String) processCtx.getKnowledgeRuntime().getEnvironment().get(EnvironmentName.DEPLOYMENT_ID);
if (deploymentId != null) {
groupName = deploymentId;
}
} else if (ctx instanceof NamedJobContext) {
jobname = ((NamedJobContext) ctx).getJobName();
String deploymentId = ((NamedJobContext) ctx).getDeploymentId();
if (deploymentId != null) {
groupName = deploymentId;
}
} else {
jobname = "Timer-" + ctx.getClass().getSimpleName() + "-" + id;
}
logger.debug("Scheduling timer with name " + jobname);
// check if this scheduler already has such job registered if so there is no need to schedule it again
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey(jobname, groupName));
if (jobDetail != null) {
TimerJobInstance timerJobInstance = (TimerJobInstance) jobDetail.getJobDataMap().get("timerJobInstance");
return timerJobInstance.getJobHandle();
}
} catch (SchedulerException e) {
}
GlobalQuartzJobHandle quartzJobHandle = new GlobalQuartzJobHandle(id, jobname, groupName);
TimerJobInstance jobInstance = globalTimerService.getTimerJobFactoryManager().createTimerJobInstance(job, ctx, trigger, quartzJobHandle, (InternalSchedulerService) globalTimerService);
quartzJobHandle.setTimerJobInstance((TimerJobInstance) jobInstance);
interceptor.internalSchedule(jobInstance);
return quartzJobHandle;
}
use of org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext in project jbpm by kiegroup.
the class ThreadPoolSchedulerService method removeJob.
@Override
public boolean removeJob(JobHandle jobHandle) {
if (jobHandle == null) {
return false;
}
jobHandle.setCancel(true);
JobContext jobContext = ((GlobalJDKJobHandle) jobHandle).getTimerJobInstance().getJobContext();
try {
ProcessJobContext processCtx = null;
if (jobContext instanceof SelfRemovalJobContext) {
processCtx = (ProcessJobContext) ((SelfRemovalJobContext) jobContext).getJobContext();
} else {
processCtx = (ProcessJobContext) jobContext;
}
String jobname = processCtx.getSessionId() + "-" + processCtx.getProcessInstanceId() + "-" + processCtx.getTimer().getId();
if (processCtx instanceof StartProcessJobContext) {
jobname = "StartProcess-" + ((StartProcessJobContext) processCtx).getProcessId() + "-" + processCtx.getTimer().getId();
}
activeTimer.remove(jobname);
globalTimerService.getTimerJobFactoryManager().removeTimerJobInstance(((GlobalJDKJobHandle) jobHandle).getTimerJobInstance());
} catch (ClassCastException e) {
// do nothing in case ProcessJobContext was not given
}
boolean removed = this.scheduler.remove((Runnable) ((GlobalJDKJobHandle) jobHandle).getFuture());
return removed;
}
Aggregations