SingletonRuntimeManager extends AbstractRuntimeManager { @Override public void close() { if (singleton == null) { return; } super.close(); try { removeRuntimeFromTaskService(); } catch (UnsupportedOperationException e) { logger.debug("Exception while closing task service, was it initialized? {}", e.getMessage()); } if (this.singleton instanceof Disposable) { ((Disposable) this.singleton).dispose(); } factory.close(); this.singleton = null; } SingletonRuntimeManager();  SingletonRuntimeManager(RuntimeEnvironment environment, SessionFactory factory, TaskServiceFactory taskServiceFactory, String identifier); void init(); @Override void activate(); @Override void deactivate(); @SuppressWarnings("rawtypes") @Override RuntimeEngine getRuntimeEngine(Context context); @Override void signalEvent(String type, Object event); @Override void validate(KieSession ksession, Context<?> context); @Override void disposeRuntimeEngine(RuntimeEngine runtime); @Override void close(); SessionFactory getFactory(); void setFactory(SessionFactory factory); TaskServiceFactory getTaskServiceFactory(); void setTaskServiceFactory(TaskServiceFactory taskServiceFactory);  }
@Test public void testCreationOfDuplicatedManagers() { RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get() .newDefaultBuilder() .userGroupCallback(userGroupCallback) .addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2) .get(); manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment); assertNotNull(manager); try { RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment); fail("Should fail as it's not allowed to have singleton manager with same identifier"); } catch (IllegalStateException e) { } manager.close(); manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment); assertNotNull(manager); }