Listeners.registerListener(_processEventListener, session.getStateful());
// TODO: the use of BPMRuntimeEnvironment should be removed after SWITCHYARD-1584,
// and the RuntimeEnvironmentBuilderFactory and RuntimeManagerFactory should be used
final KieSession kieSession = session.getStateful();
final String deploymentId = getDeploymentId();
final RuntimeManagerRegistry runtimeManagerRegistry = RuntimeManagerRegistry.get();
if (runtimeManagerRegistry.isRegistered(deploymentId)) {
runtimeManagerRegistry.remove(deploymentId);
}
RuntimeEnvironment runtimeEnvironment = new BPMRuntimeEnvironment(session.getStateful(), _entityManagerFactory, _userGroupCallback, getLoader());
AbstractRuntimeManager runtimeManager = new AbstractRuntimeManager(runtimeEnvironment, deploymentId) {
private RuntimeEngineImpl _runtimeEngine = null;
@Override
public void init() {
_runtimeEngine = new RuntimeEngineImpl(kieSession, _taskService) {
@Override
public void dispose() {
// no-op
}
};
_runtimeEngine.setManager(this);
}
@Override
public void validate(KieSession ksession, org.kie.api.runtime.manager.Context<?> context) throws IllegalStateException {
// no-op
}
@Override
public RuntimeEngine getRuntimeEngine(org.kie.api.runtime.manager.Context<?> context) {
return _runtimeEngine;
}
@Override
public void disposeRuntimeEngine(RuntimeEngine runtime) {
// no-op
}
@Override
public void close() {
runtimeManagerRegistry.remove(deploymentId);
}
};
runtimeManager.init();
if (!runtimeManagerRegistry.isRegistered(deploymentId)) {
runtimeManagerRegistry.register(runtimeManager);
session.addDisposals(new KnowledgeDisposal() {
@Override
public void dispose() {
runtimeManagerRegistry.remove(deploymentId);
}
});
}
WorkItemHandlers.registerWorkItemHandlers(getModel(), getLoader(), session.getStateful(), runtimeManager, getServiceDomain());
}