Search in sources :

Example 1 with Disposable

use of org.kie.internal.runtime.manager.Disposable 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 2 with Disposable

use of org.kie.internal.runtime.manager.Disposable 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 3 with Disposable

use of org.kie.internal.runtime.manager.Disposable 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 4 with Disposable

use of org.kie.internal.runtime.manager.Disposable in project jbpm by kiegroup.

the class AbstractRuntimeManager method configureRuntimeOnTaskService.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void configureRuntimeOnTaskService(InternalTaskService internalTaskService, RuntimeEngine engine) {
    if (internalTaskService != null) {
        ExternalTaskEventListener listener = new ExternalTaskEventListener();
        if (internalTaskService instanceof EventService) {
            ((EventService) internalTaskService).registerTaskEventListener(listener);
        }
        // register task listeners if any
        RegisterableItemsFactory factory = environment.getRegisterableItemsFactory();
        for (TaskLifeCycleEventListener taskListener : factory.getTaskListeners()) {
            ((EventService<TaskLifeCycleEventListener>) internalTaskService).registerTaskEventListener(taskListener);
        }
        if (engine != null && engine instanceof Disposable) {
            ((Disposable) engine).addDisposeListener(new DisposeListener() {

                @Override
                public void onDispose(RuntimeEngine runtime) {
                    if (runtime.getTaskService() instanceof EventService) {
                        ((EventService) runtime.getTaskService()).clearTaskEventListeners();
                        ;
                    }
                }
            });
        }
    }
}
Also used : Disposable(org.kie.internal.runtime.manager.Disposable) DisposeListener(org.kie.internal.runtime.manager.DisposeListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExternalTaskEventListener(org.jbpm.services.task.wih.ExternalTaskEventListener) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) EventService(org.kie.internal.task.api.EventService) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Aggregations

Disposable (org.kie.internal.runtime.manager.Disposable)4 TimerService (org.drools.core.time.TimerService)3 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)3 InMemoryMapper (org.jbpm.runtime.manager.impl.mapper.InMemoryMapper)2 ExternalTaskEventListener (org.jbpm.services.task.wih.ExternalTaskEventListener)1 RegisterableItemsFactory (org.kie.api.runtime.manager.RegisterableItemsFactory)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)1 DisposeListener (org.kie.internal.runtime.manager.DisposeListener)1 InternalRegisterableItemsFactory (org.kie.internal.runtime.manager.InternalRegisterableItemsFactory)1 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)1 EventService (org.kie.internal.task.api.EventService)1