Search in sources :

Example 11 with GlobalTimerService

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

the class GlobalJpaTimerJobInstance method call.

@Override
public Void call() throws Exception {
    AsyncExecutionMarker.markAsync();
    ExecutableRunner runner = null;
    TransactionManager jtaTm = null;
    boolean success = false;
    try {
        JDKCallableJobCommand command = new JDKCallableJobCommand(this);
        if (scheduler == null) {
            scheduler = (InternalSchedulerService) TimerServiceRegistry.getInstance().get(timerServiceId);
        }
        if (scheduler == null) {
            throw new RuntimeException("No scheduler found for " + timerServiceId);
        }
        jtaTm = startTxIfNeeded(((GlobalTimerService) scheduler).getRuntimeManager().getEnvironment().getEnvironment());
        runner = ((GlobalTimerService) scheduler).getRunner(getJobContext());
        runner.execute(command);
        GlobalJPATimerJobFactoryManager timerService = ((GlobalJPATimerJobFactoryManager) ((GlobalTimerService) scheduler).getTimerJobFactoryManager());
        timerService.removeTimerJobInstance(((DefaultJobHandle) getJobHandle()).getTimerJobInstance());
        success = true;
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        success = false;
        throw e;
    } finally {
        AsyncExecutionMarker.reset();
        if (runner != null && runner instanceof DisposableCommandService) {
            if (allowedToDispose(((DisposableCommandService) runner).getEnvironment())) {
                logger.debug("Allowed to dispose command service from global timer job instance");
                ((DisposableCommandService) runner).dispose();
            }
        }
        closeTansactionIfNeeded(jtaTm, success);
    }
}
Also used : DisposableCommandService(org.jbpm.process.core.timer.impl.GlobalTimerService.DisposableCommandService) TransactionManager(org.drools.persistence.api.TransactionManager) ContainerManagedTransactionManager(org.jbpm.persistence.jta.ContainerManagedTransactionManager) JDKCallableJobCommand(org.drools.persistence.jpa.JDKCallableJobCommand) ExecutableRunner(org.kie.api.runtime.ExecutableRunner) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService)

Example 12 with GlobalTimerService

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

the class AbstractRuntimeManager method close.

public void close(boolean removeJobs) {
    cacheManager.dispose();
    environment.close();
    registry.remove(identifier);
    TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null) {
        try {
            if (removeJobs && timerService instanceof GlobalTimerService) {
                ((GlobalTimerService) timerService).destroy();
            }
            timerService.shutdown();
            GlobalSchedulerService schedulerService = ((SchedulerProvider) environment).getSchedulerService();
            if (schedulerService != null) {
                schedulerService.shutdown();
            }
        } finally {
            TimerServiceRegistry.getInstance().remove(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
        }
    }
    this.closed = true;
}
Also used : GlobalSchedulerService(org.jbpm.process.core.timer.GlobalSchedulerService) SchedulerProvider(org.jbpm.runtime.manager.api.SchedulerProvider) 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