Search in sources :

Example 1 with GlobalTimerService

use of org.jbpm.process.core.timer.impl.GlobalTimerService in project jbpm by kiegroup.

the class RuntimeManagerFactoryImpl method initTimerService.

protected void initTimerService(RuntimeEnvironment environment, RuntimeManager manager) {
    if (environment instanceof SchedulerProvider) {
        GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService();
        if (schedulerService != null) {
            TimerService globalTs = new GlobalTimerService(manager, schedulerService);
            String timerServiceId = manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX;
            // and register it in the registry under 'default' key
            TimerServiceRegistry.getInstance().registerTimerService(timerServiceId, globalTs);
            ((SimpleRuntimeEnvironment) environment).addToConfiguration("drools.timerService", "new org.jbpm.process.core.timer.impl.RegisteredTimerServiceDelegate(\"" + timerServiceId + "\")");
            if (!schedulerService.isTransactional()) {
                schedulerService.setInterceptor(new TransactionAwareSchedulerServiceInterceptor(environment, manager, schedulerService));
            }
        }
    }
}
Also used : GlobalSchedulerService(org.jbpm.process.core.timer.GlobalSchedulerService) SchedulerProvider(org.jbpm.runtime.manager.api.SchedulerProvider) TransactionAwareSchedulerServiceInterceptor(org.jbpm.runtime.manager.impl.tx.TransactionAwareSchedulerServiceInterceptor) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 2 with GlobalTimerService

use of org.jbpm.process.core.timer.impl.GlobalTimerService in project jbpm by kiegroup.

the class PerCaseRuntimeManager method disposeRuntimeEngine.

@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
    if (isClosed()) {
        throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
    }
    try {
        if (canDispose(runtime)) {
            removeLocalRuntime(runtime);
            Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
            releaseAndCleanLock(ksessionId, runtime);
            if (runtime instanceof Disposable) {
                // special handling for in memory to not allow to dispose if there is any context in the mapper
                if (mapper instanceof InMemoryMapper && ((InMemoryMapper) mapper).hasContext(ksessionId)) {
                    return;
                }
                ((Disposable) runtime).dispose();
            }
            if (ksessionId != null) {
                TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
                if (timerService != null) {
                    if (timerService instanceof GlobalTimerService) {
                        ((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
                    }
                }
            }
        }
    } catch (Exception e) {
        releaseAndCleanLock(runtime);
        removeLocalRuntime(runtime);
        throw new RuntimeException(e);
    }
}
Also used : Disposable(org.kie.internal.runtime.manager.Disposable) InMemoryMapper(org.jbpm.runtime.manager.impl.mapper.InMemoryMapper) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 3 with GlobalTimerService

use of org.jbpm.process.core.timer.impl.GlobalTimerService in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManager method disposeRuntimeEngine.

@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
    if (isClosed()) {
        throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
    }
    try {
        if (canDispose(runtime)) {
            removeLocalRuntime(runtime);
            Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
            if (runtime instanceof Disposable) {
                // special handling for in memory to not allow to dispose if there is any context in the mapper
                if (mapper instanceof InMemoryMapper && ((InMemoryMapper) mapper).hasContext(ksessionId)) {
                    return;
                }
                ((Disposable) runtime).dispose();
            }
            if (ksessionId != null) {
                TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
                if (timerService != null) {
                    if (timerService instanceof GlobalTimerService) {
                        ((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
                    }
                }
            }
            releaseAndCleanLock(runtime);
        }
    } catch (Exception e) {
        releaseAndCleanLock(runtime);
        removeLocalRuntime(runtime);
        throw new RuntimeException(e);
    }
}
Also used : Disposable(org.kie.internal.runtime.manager.Disposable) InMemoryMapper(org.jbpm.runtime.manager.impl.mapper.InMemoryMapper) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 4 with GlobalTimerService

use of org.jbpm.process.core.timer.impl.GlobalTimerService in project jbpm by kiegroup.

the class PerRequestRuntimeManager method disposeRuntimeEngine.

@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
    if (isClosed()) {
        throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
    }
    try {
        if (canDispose(runtime)) {
            local.get().remove(identifier);
            try {
                Long ksessionId = ((RuntimeEngineImpl) runtime).getKieSessionId();
                factory.onDispose(ksessionId);
                if (canDestroy(runtime)) {
                    runtime.getKieSession().destroy();
                } else {
                    if (runtime instanceof Disposable) {
                        ((Disposable) runtime).dispose();
                    }
                }
                if (ksessionId != null) {
                    TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
                    if (timerService != null) {
                        if (timerService instanceof GlobalTimerService) {
                            ((GlobalTimerService) timerService).clearTimerJobInstances(ksessionId);
                        }
                    }
                }
            } catch (Exception e) {
                // do nothing
                if (runtime instanceof Disposable) {
                    ((Disposable) runtime).dispose();
                }
            }
        }
    } catch (Exception e) {
        local.get().remove(identifier);
        throw new RuntimeException(e);
    }
}
Also used : Disposable(org.kie.internal.runtime.manager.Disposable) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 5 with GlobalTimerService

use of org.jbpm.process.core.timer.impl.GlobalTimerService in project jbpm by kiegroup.

the class TaskDeadlinesServiceImpl method unschedule.

public void unschedule(long taskId, Deadline deadline, DeadlineType type) {
    Task task = persistenceContext.findTask(taskId);
    String deploymentId = task.getTaskData().getDeploymentId();
    Deadlines deadlines = ((InternalTask) task).getDeadlines();
    TimerService timerService = TimerServiceRegistry.getInstance().get(deploymentId + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null && timerService instanceof GlobalTimerService) {
        TaskDeadlineJob deadlineJob = new TaskDeadlineJob(taskId, deadline.getId(), type, deploymentId, task.getTaskData().getProcessInstanceId());
        logger.debug("unscheduling timer job for deadline {} {} and task {}  using timer service {}", deadlineJob.getId(), deadline.getId(), taskId, timerService);
        JobHandle jobHandle = jobHandles.remove(deadlineJob.getId());
        if (jobHandle == null) {
            jobHandle = ((GlobalTimerService) timerService).buildJobHandleForContext(new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId));
        }
        timerService.removeJob(jobHandle);
        // mark the deadlines so they won't be rescheduled again
        deadline.setEscalated(true);
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) Task(org.kie.api.task.model.Task) InternalTask(org.kie.internal.task.api.model.InternalTask) Deadlines(org.kie.internal.task.api.model.Deadlines) InternalTask(org.kie.internal.task.api.model.InternalTask) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Aggregations

GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)12 TimerService (org.drools.core.time.TimerService)11 ArrayList (java.util.ArrayList)3 JobHandle (org.drools.core.time.JobHandle)3 Test (org.junit.Test)3 Task (org.kie.api.task.model.Task)3 Disposable (org.kie.internal.runtime.manager.Disposable)3 InternalTask (org.kie.internal.task.api.model.InternalTask)3 List (java.util.List)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 GlobalSchedulerService (org.jbpm.process.core.timer.GlobalSchedulerService)2 SchedulerProvider (org.jbpm.runtime.manager.api.SchedulerProvider)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2 InMemoryMapper (org.jbpm.runtime.manager.impl.mapper.InMemoryMapper)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)2 Ignore (org.junit.Ignore)2 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)2 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)2 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)2 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)2