Search in sources :

Example 11 with TimerJobInstance

use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.

the class TransactionalThreadPoolSchedulerService method internalSchedule.

@Override
public void internalSchedule(TimerJobInstance timerJobInstance) {
    TimerJobInstance proxy = (TimerJobInstance) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { Callable.class, Comparable.class, TimerJobInstance.class, Serializable.class }, new TransactionalTimerJobInstance(timerJobInstance));
    super.internalSchedule(proxy);
}
Also used : Serializable(java.io.Serializable) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) GlobalJpaTimerJobInstance(org.jbpm.persistence.timer.GlobalJpaTimerJobInstance) Callable(java.util.concurrent.Callable)

Example 12 with TimerJobInstance

use of org.drools.core.time.impl.TimerJobInstance 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 13 with TimerJobInstance

use of org.drools.core.time.impl.TimerJobInstance 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 14 with TimerJobInstance

use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.

the class EJBTimerScheduler method getTimerByName.

public TimerJobInstance getTimerByName(String jobName) {
    if (localCache.containsKey(jobName)) {
        logger.debug("Found job {} in cache returning", jobName);
        return localCache.get(jobName);
    }
    TimerJobInstance found = null;
    for (Timer timer : timerService.getTimers()) {
        try {
            Serializable info = timer.getInfo();
            if (info instanceof EjbTimerJob) {
                EjbTimerJob job = (EjbTimerJob) info;
                EjbGlobalJobHandle handle = (EjbGlobalJobHandle) job.getTimerJobInstance().getJobHandle();
                localCache.putIfAbsent(jobName, handle.getTimerJobInstance());
                if (handle.getUuid().equals(jobName)) {
                    logger.debug("Job  {} does match timer and is going to be returned", jobName);
                    found = handle.getTimerJobInstance();
                }
            }
        } catch (NoSuchObjectLocalException e) {
            logger.debug("Timer info for {} was not found ", timer);
        }
    }
    return found;
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) Serializable(java.io.Serializable) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) Timer(javax.ejb.Timer)

Example 15 with TimerJobInstance

use of org.drools.core.time.impl.TimerJobInstance in project jbpm by kiegroup.

the class EjbSchedulerService method scheduleJob.

@Override
public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
    Long id = idCounter.getAndIncrement();
    String jobName = getJobName(ctx, id);
    EjbGlobalJobHandle jobHandle = new EjbGlobalJobHandle(id, jobName, ((GlobalTimerService) globalTimerService).getTimerServiceId());
    TimerJobInstance jobInstance = null;
    // if so skip the check by timer name as it has no way to exist
    if (!isNewTimer(ctx)) {
        jobInstance = scheduler.getTimerByName(jobName);
        if (jobInstance != null) {
            return jobInstance.getJobHandle();
        }
    }
    jobInstance = globalTimerService.getTimerJobFactoryManager().createTimerJobInstance(job, ctx, trigger, jobHandle, (InternalSchedulerService) globalTimerService);
    jobHandle.setTimerJobInstance((TimerJobInstance) jobInstance);
    interceptor.internalSchedule(jobInstance);
    return jobHandle;
}
Also used : TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) InternalSchedulerService(org.drools.core.time.InternalSchedulerService) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

TimerJobInstance (org.drools.core.time.impl.TimerJobInstance)15 SelfRemovalJobContext (org.drools.core.time.SelfRemovalJobContext)5 ProcessJobContext (org.jbpm.process.instance.timer.TimerManager.ProcessJobContext)5 ArrayList (java.util.ArrayList)4 JobContext (org.drools.core.time.JobContext)4 TimerService (org.drools.core.time.TimerService)4 Test (org.junit.Test)4 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)4 UserTransaction (javax.transaction.UserTransaction)3 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)3 KieSession (org.kie.api.runtime.KieSession)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Callable (java.util.concurrent.Callable)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)2 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)2 StartProcessJobContext (org.jbpm.process.instance.timer.TimerManager.StartProcessJobContext)2