@Override public RuntimeEngine getRuntimeEngine(Context<?> context) { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); } checkPermission(); RuntimeEngine runtime = null; if (local.get() != null) { return local.get(); } if (engineInitEager) { InternalTaskService internalTaskService = (InternalTaskService) taskServiceFactory.newTaskService(); runtime = new RuntimeEngineImpl(factory.newKieSession(), internalTaskService); ((RuntimeEngineImpl) runtime).setManager(this); configureRuntimeOnTaskService(internalTaskService, runtime); registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime)); registerDisposeCallback( runtime, new DestroySessionTransactionSynchronization(runtime.getKieSession())); registerItems(runtime); attachManager(runtime); } else { runtime = new RuntimeEngineImpl(context, new PerRequestInitializer()); ((RuntimeEngineImpl) runtime).setManager(this); } local.set(runtime); return runtime; }
@Override public void close() { try { if (!(taskServiceFactory instanceof LocalTaskServiceFactory)) { // if it's CDI based (meaning single application scoped bean) we need to unregister context removeRuntimeFromTaskService((InternalTaskService) taskServiceFactory.newTaskService()); } } catch (Exception e) { // do nothing } super.close(); factory.close(); }