use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext in project jbpm by kiegroup.
the class GlobalJPATimerJobFactoryManager method createTimerJobInstance.
public TimerJobInstance createTimerJobInstance(Job job, JobContext ctx, Trigger trigger, JobHandle handle, InternalSchedulerService scheduler) {
long sessionId = -1;
if (ctx instanceof ProcessJobContext) {
sessionId = ((ProcessJobContext) ctx).getSessionId();
Map<Long, TimerJobInstance> instances = timerInstances.get(sessionId);
if (instances == null) {
instances = new ConcurrentHashMap<Long, TimerJobInstance>();
timerInstances.put(sessionId, instances);
}
}
ctx.setJobHandle(handle);
GlobalJpaTimerJobInstance jobInstance = new GlobalJpaTimerJobInstance(new SelfRemovalJob(job), new SelfRemovalJobContext(ctx, emptyStore), trigger, handle, scheduler);
return jobInstance;
}
use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext 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.ProcessJobContext 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.ProcessJobContext in project jbpm by kiegroup.
the class GlobalTimerService method scheduleJob.
@Override
public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
if (ctx instanceof ProcessJobContext) {
ProcessJobContext processCtx = (ProcessJobContext) ctx;
List<GlobalJobHandle> jobHandles = timerJobsPerSession.get(processCtx.getSessionId());
if (jobHandles == null) {
jobHandles = new CopyOnWriteArrayList<GlobalJobHandle>();
timerJobsPerSession.put(processCtx.getSessionId(), jobHandles);
} else {
// check if the given job is already scheduled
for (GlobalJobHandle handle : jobHandles) {
long timerId = handle.getTimerId();
if (timerId == processCtx.getTimer().getId()) {
// this timer job is already registered
return handle;
}
}
}
GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger);
if (jobHandle != null) {
jobHandles.add(jobHandle);
}
return jobHandle;
}
GlobalJobHandle jobHandle = (GlobalJobHandle) this.schedulerService.scheduleJob(job, ctx, trigger);
return jobHandle;
}
use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext in project jbpm by kiegroup.
the class GlobalTimerService method getRunner.
public ExecutableRunner getRunner(JobContext jobContext) {
JobContext ctxorig = jobContext;
if (ctxorig instanceof SelfRemovalJobContext) {
ctxorig = ((SelfRemovalJobContext) ctxorig).getJobContext();
}
ProcessJobContext ctx = null;
if (ctxorig instanceof ProcessJobContext) {
ctx = (ProcessJobContext) ctxorig;
} else if (ctxorig instanceof NamedJobContext) {
return getRunner(((NamedJobContext) ctxorig).getProcessInstanceId(), ctx);
} else {
return getRunner();
}
return getRunner(ctx.getProcessInstanceId(), ctx);
}
Aggregations