public ServiceResponse<Void> disposeContainer(String containerId) { try { KieContainerInstance kci = (KieContainerInstance) context.removeContainer(containerId); if (kci != null) { synchronized (kci) { kci.setStatus(KieContainerStatus.DISPOSING); // just in case if (kci.getKieContainer() != null) { InternalKieContainer kieContainer = kci.getKieContainer(); kci.setKieContainer(null); // helps reduce concurrent access issues try { // this may fail, but we already removed the container from the registry kieContainer.dispose(); } catch (Exception e) { logger.warn( "Container '" + containerId + "' disposed, but an unnexpected exception was raised", e); return new ServiceResponse<Void>( ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " disposed, but exception was raised: " + e.getClass().getName() + ": " + e.getMessage()); } return new ServiceResponse<Void>( ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully disposed."); } else { return new ServiceResponse<Void>( ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated."); } } } else { return new ServiceResponse<Void>( ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated."); } } catch (Exception e) { logger.error("Error disposing Container '" + containerId + "'", e); return new ServiceResponse<Void>( ServiceResponse.ResponseType.FAILURE, "Error disposing container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage()); } }