Search in sources :

Example 1 with DisposableCommandService

use of org.jbpm.process.core.timer.impl.GlobalTimerService.DisposableCommandService 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)

Aggregations

TransactionManager (org.drools.persistence.api.TransactionManager)1 JDKCallableJobCommand (org.drools.persistence.jpa.JDKCallableJobCommand)1 ContainerManagedTransactionManager (org.jbpm.persistence.jta.ContainerManagedTransactionManager)1 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)1 DisposableCommandService (org.jbpm.process.core.timer.impl.GlobalTimerService.DisposableCommandService)1 ExecutableRunner (org.kie.api.runtime.ExecutableRunner)1