Search in sources :

Example 1 with ProcessJobContext

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;
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) SelfRemovalJob(org.drools.core.time.SelfRemovalJob) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext)

Example 2 with ProcessJobContext

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;
    }
}
Also used : StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) Date(java.util.Date)

Example 3 with ProcessJobContext

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;
}
Also used : StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) NamedJobContext(org.jbpm.process.core.timer.NamedJobContext)

Example 4 with ProcessJobContext

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;
}
Also used : ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext)

Example 5 with ProcessJobContext

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);
}
Also used : ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) NamedJobContext(org.jbpm.process.core.timer.NamedJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) NamedJobContext(org.jbpm.process.core.timer.NamedJobContext) JobContext(org.drools.core.time.JobContext)

Aggregations

ProcessJobContext (org.jbpm.process.instance.timer.TimerManager.ProcessJobContext)10 SelfRemovalJobContext (org.drools.core.time.SelfRemovalJobContext)5 TimerJobInstance (org.drools.core.time.impl.TimerJobInstance)5 StartProcessJobContext (org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext)5 JobContext (org.drools.core.time.JobContext)4 NamedJobContext (org.jbpm.process.core.timer.NamedJobContext)4 Date (java.util.Date)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SelfRemovalJob (org.drools.core.time.SelfRemovalJob)1 JobDetail (org.quartz.JobDetail)1 SchedulerException (org.quartz.SchedulerException)1