@Override public RuntimeEngine getRuntimeEngine(Context<?> context) { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); checkPermission(); RuntimeEngine runtime = null; Object contextId = context.getContextId(); ksessionId = ksession.getIdentifier(); } else { RuntimeEngine localRuntime = findLocalRuntime(contextId); if (localRuntime != null) { return localRuntime; InternalTaskService internalTaskService = newTaskService(taskServiceFactory); runtime = new RuntimeEngineImpl(ksession, internalTaskService); ((RuntimeEngineImpl) runtime).setManager(this); ((RuntimeEngineImpl) runtime).setContext(context); configureRuntimeOnTaskService(internalTaskService, runtime); registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), ksession.getEnvironment()); registerItems(runtime); attachManager(runtime); ksession.addEventListener(new MaintainMappingListener(ksessionId, runtime, this.identifier)); } else { RuntimeEngine localRuntime = findLocalRuntime(contextId); if (localRuntime != null) { return localRuntime; createLockOnGetEngine(context, runtime);
public RuntimeManager newPerProcessInstanceRuntimeManager(RuntimeEnvironment environment, String identifier) { SessionFactory factory = getSessionFactory(environment, identifier); TaskServiceFactory taskServiceFactory = getTaskServiceFactory(environment); RuntimeManager manager = new PerProcessInstanceRuntimeManager(environment, factory, taskServiceFactory, identifier); initTimerService(environment, manager); ((AbstractRuntimeManager) manager).init(); return manager; }
@Override public void disposeRuntimeEngine(RuntimeEngine runtime) { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); if (canDispose(runtime)) { removeLocalRuntime(runtime); TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); if (timerService != null) { if (timerService instanceof GlobalTimerService) { releaseAndCleanLock(runtime); releaseAndCleanLock(runtime); removeLocalRuntime(runtime); throw new RuntimeException(e);
@Override public TaskService initTaskService(Context<?> context, InternalRuntimeManager manager, RuntimeEngine engine) { InternalTaskService internalTaskService = newTaskService(taskServiceFactory); if (internalTaskService != null) { registerDisposeCallback(engine, new DisposeSessionTransactionSynchronization(manager, engine), ((CommandBasedTaskService) internalTaskService).getEnvironment()); configureRuntimeOnTaskService(internalTaskService, engine); } return internalTaskService; }
RuntimeEngine runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get()); runtimeEngine.getKieSession().signalEvent(type, event); disposeRuntimeEngine(runtimeEngine); List<String> processInstances = ((InternalMapper) mapper).findContextIdForEvent(type, getIdentifier()); for (String piId : processInstances) { runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(Long.parseLong(piId))); runtimeEngine.getKieSession().signalEvent(type, event); disposeRuntimeEngine(runtimeEngine);
Long found = mapper.findMapping(context, manager.getIdentifier()); if (found == null) { removeLocalRuntime(engine); throw new SessionNotFoundException("No session found for context " + context.getContextId()); ksessionId = ksession.getIdentifier(); } else { RuntimeEngine localRuntime = ((PerProcessInstanceRuntimeManager)manager).findLocalRuntime(contextId); if (localRuntime != null && ((RuntimeEngineImpl)engine).internalGetKieSession() != null) { return localRuntime.getKieSession(); registerItems(engine); attachManager(engine); registerDisposeCallback(engine, new DisposeSessionTransactionSynchronization(manager, engine), ksession.getEnvironment()); ksession.addEventListener(new MaintainMappingListener(ksessionId, engine, manager.getIdentifier())); return ksession;
@Override public void beforeProcessStarted(ProcessStartedEvent event) { mapper.saveMapping(new EnvironmentAwareProcessInstanceContext( event.getKieRuntime().getEnvironment(), event.getProcessInstance().getId()), ksessionId, managerId); saveLocalRuntime(event.getProcessInstance().getId(), runtime); ((RuntimeEngineImpl)runtime).setContext(ProcessInstanceIdContext.get(event.getProcessInstance().getId())); createLockOnNewProcessInstance(event.getProcessInstance().getId(), runtime); }
@Override public void init() { TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader())); boolean owner = false; TransactionManager tm = null; if (environment.usePersistence()) { tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
Object cachedRE1 = ((PerProcessInstanceRuntimeManager) manager).findLocalRuntime(pi1.getId()); assertNull(cachedRE1); Object cachedRE2 = ((PerProcessInstanceRuntimeManager) manager).findLocalRuntime(pi2.getId()); assertNull(cachedRE2); cachedRE1 = ((PerProcessInstanceRuntimeManager) manager).findLocalRuntime(pi1.getId()); assertNull(cachedRE1); cachedRE2 = ((PerProcessInstanceRuntimeManager) manager).findLocalRuntime(pi2.getId()); assertNull(cachedRE2); manager.close();
Long found = mapper.findMapping(context, manager.getIdentifier()); if (found == null) { removeLocalRuntime(engine); throw new SessionNotFoundException("No session found for context " + context.getContextId()); ksessionId = ksession.getIdentifier(); } else { RuntimeEngine localRuntime = ((PerProcessInstanceRuntimeManager)manager).findLocalRuntime(contextId); if (localRuntime != null && ((RuntimeEngineImpl)engine).internalGetKieSession() != null) { return localRuntime.getKieSession(); registerItems(engine); attachManager(engine); registerDisposeCallback(engine, new DisposeSessionTransactionSynchronization(manager, engine), ksession.getEnvironment()); ksession.addEventListener(new MaintainMappingListener(ksessionId, engine, manager.getIdentifier())); return ksession;
@Override public TaskService initTaskService(Context<?> context, InternalRuntimeManager manager, RuntimeEngine engine) { InternalTaskService internalTaskService = newTaskService(taskServiceFactory); if (internalTaskService != null) { registerDisposeCallback(engine, new DisposeSessionTransactionSynchronization(manager, engine), ((CommandBasedTaskService) internalTaskService).getEnvironment()); configureRuntimeOnTaskService(internalTaskService, engine); } return internalTaskService; }
RuntimeEngine runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get()); runtimeEngine.getKieSession().signalEvent(type, event); disposeRuntimeEngine(runtimeEngine); List<String> processInstances = ((InternalMapper) mapper).findContextIdForEvent(type, getIdentifier()); for (String piId : processInstances) { runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(Long.parseLong(piId))); runtimeEngine.getKieSession().signalEvent(type, event); disposeRuntimeEngine(runtimeEngine);
@Override public void beforeProcessStarted(ProcessStartedEvent event) { mapper.saveMapping(new EnvironmentAwareProcessInstanceContext( event.getKieRuntime().getEnvironment(), event.getProcessInstance().getId()), ksessionId, managerId); saveLocalRuntime(event.getProcessInstance().getId(), runtime); ((RuntimeEngineImpl)runtime).setContext(ProcessInstanceIdContext.get(event.getProcessInstance().getId())); createLockOnNewProcessInstance(event.getProcessInstance().getId(), runtime); }
@Override public void init() { TaskContentRegistry.get().addMarshallerContext(getIdentifier(), new ContentMarshallerContext(environment.getEnvironment(), environment.getClassLoader())); boolean owner = false; TransactionManager tm = null; if (environment.usePersistence()) { tm = getTransactionManagerInternal(environment.getEnvironment()); owner = tm.begin();
@Override public RuntimeEngine getRuntimeEngine(Context<?> context) { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); checkPermission(); RuntimeEngine runtime = null; Object contextId = context.getContextId(); ksessionId = ksession.getIdentifier(); } else { RuntimeEngine localRuntime = findLocalRuntime(contextId); if (localRuntime != null) { return localRuntime; InternalTaskService internalTaskService = newTaskService(taskServiceFactory); runtime = new RuntimeEngineImpl(ksession, internalTaskService); ((RuntimeEngineImpl) runtime).setManager(this); ((RuntimeEngineImpl) runtime).setContext(context); configureRuntimeOnTaskService(internalTaskService, runtime); registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), ksession.getEnvironment()); registerItems(runtime); attachManager(runtime); ksession.addEventListener(new MaintainMappingListener(ksessionId, runtime, this.identifier)); } else { RuntimeEngine localRuntime = findLocalRuntime(contextId); if (localRuntime != null) { return localRuntime; createLockOnGetEngine(context, runtime);
@Override public void disposeRuntimeEngine(RuntimeEngine runtime) { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); if (canDispose(runtime)) { removeLocalRuntime(runtime); TimerService timerService = TimerServiceRegistry.getInstance().get(getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX); if (timerService != null) { if (timerService instanceof GlobalTimerService) { releaseAndCleanLock(runtime); releaseAndCleanLock(runtime); removeLocalRuntime(runtime); throw new RuntimeException(e);
public RuntimeManager newPerProcessInstanceRuntimeManager(RuntimeEnvironment environment, String identifier) { SessionFactory factory = getSessionFactory(environment, identifier); TaskServiceFactory taskServiceFactory = getTaskServiceFactory(environment); RuntimeManager manager = new PerProcessInstanceRuntimeManager(environment, factory, taskServiceFactory, identifier); initTimerService(environment, manager); ((AbstractRuntimeManager) manager).init(); return manager; }