Search in sources :

Example 6 with ProcessJobContext

use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext 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;
}
Also used : StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) JobDetail(org.quartz.JobDetail) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) SchedulerException(org.quartz.SchedulerException) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) NamedJobContext(org.jbpm.process.core.timer.NamedJobContext)

Example 7 with ProcessJobContext

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

Example 8 with ProcessJobContext

use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext in project jbpm by kiegroup.

the class GlobalJPATimerJobFactoryManager method addTimerJobInstance.

public void addTimerJobInstance(TimerJobInstance instance) {
    JobContext ctx = instance.getJobContext();
    if (ctx instanceof SelfRemovalJobContext) {
        ctx = ((SelfRemovalJobContext) ctx).getJobContext();
    }
    Map<Long, TimerJobInstance> instances = null;
    if (ctx instanceof ProcessJobContext) {
        long sessionId = ((ProcessJobContext) ctx).getSessionId();
        instances = timerInstances.get(sessionId);
        if (instances == null) {
            instances = new ConcurrentHashMap<Long, TimerJobInstance>();
            timerInstances.put(sessionId, instances);
        }
    } else {
        instances = singleTimerInstances;
    }
    instances.put(instance.getJobHandle().getId(), instance);
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) JobContext(org.drools.core.time.JobContext)

Example 9 with ProcessJobContext

use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext in project jbpm by kiegroup.

the class GlobalJPATimerJobFactoryManager method removeTimerJobInstance.

public void removeTimerJobInstance(TimerJobInstance instance) {
    Long sessionId = null;
    JobContext ctx = instance.getJobContext();
    if (ctx instanceof SelfRemovalJobContext) {
        ctx = ((SelfRemovalJobContext) ctx).getJobContext();
    }
    Map<Long, TimerJobInstance> instances = null;
    if (ctx instanceof ProcessJobContext) {
        sessionId = ((ProcessJobContext) ctx).getSessionId();
        instances = timerInstances.get(sessionId);
        if (instances == null) {
            instances = new ConcurrentHashMap<Long, TimerJobInstance>();
            timerInstances.put(sessionId, instances);
        }
    } else {
        instances = singleTimerInstances;
    }
    instances.remove(instance.getJobHandle().getId());
    if (sessionId != null && instances.isEmpty()) {
        timerInstances.remove(sessionId);
    }
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) SelfRemovalJobContext(org.drools.core.time.SelfRemovalJobContext) ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) JobContext(org.drools.core.time.JobContext)

Example 10 with ProcessJobContext

use of org.jbpm.process.instance.timer.TimerManager.ProcessJobContext in project jbpm by kiegroup.

the class EjbSchedulerService method isNewTimer.

private boolean isNewTimer(JobContext ctx) {
    boolean isNewTimer = true;
    if (ctx instanceof ProcessJobContext) {
        ProcessJobContext processCtx = (ProcessJobContext) ctx;
        isNewTimer = processCtx.isNewTimer();
    }
    return isNewTimer;
}
Also used : ProcessJobContext(org.jbpm.process.instance.timer.TimerManager.ProcessJobContext) StartProcessJobContext(org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext)

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