* @param deploymentId The id of the deployment for the {@link RuntimeEngine}.
* @param processInstanceId The process instance id, if available.
* @return The {@link RuntimeEngine} instance.
*/
public RuntimeEngine getRuntimeEngine(String deploymentId, Long processInstanceId) {
RuntimeManager runtimeManager = getRuntimeManager(deploymentId);
if (runtimeManager == null) {
throw new DeploymentNotFoundException("No runtime manager could be found for deployment '" + deploymentId + "'.");
}
Context<?> runtimeContext;
if( runtimeManager instanceof PerProcessInstanceRuntimeManager ) {
if( processInstanceId == null || processInstanceId < 0 ) {
if( processInstanceId != null ) {
processInstanceId = null;
}
// Use the static method here instead of the constructor in order to use mock static magic in the tests
runtimeContext = ProcessInstanceIdContext.get();
} else {
runtimeContext = ProcessInstanceIdContext.get(processInstanceId);
}
} else {
runtimeContext = EmptyContext.get();
}
return runtimeManager.getRuntimeEngine(runtimeContext);
}