use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method abortWorkItem.
@Override
public void abortWorkItem(String deploymentId, Long processInstanceId, Long id) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
if (workItem == null) {
throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
}
ksession.getWorkItemManager().abortWorkItem(id);
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method getProcessInstance.
@Override
public ProcessInstance getProcessInstance(String deploymentId, Long processInstanceId) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
return ksession.getProcessInstance(processInstanceId);
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class ProcessServiceImpl method getWorkItem.
@Override
public WorkItem getWorkItem(String deploymentId, Long processInstanceId, Long id) {
DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
if (deployedUnit == null) {
throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
}
RuntimeManager manager = deployedUnit.getRuntimeManager();
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
try {
KieSession ksession = engine.getKieSession();
WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
if (workItem == null) {
throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
}
return workItem;
} catch (SessionNotFoundException e) {
throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
} finally {
disposeRuntimeEngine(manager, engine);
}
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManager method getRuntimeEngine.
@Override
public RuntimeEngine getRuntimeEngine(Context<?> context) {
if (isClosed()) {
throw new IllegalStateException("Runtime manager " + identifier + " is already closed");
}
checkPermission();
RuntimeEngine runtime = null;
Object contextId = context.getContextId();
if (!(context instanceof ProcessInstanceIdContext || context instanceof CorrelationKeyContext)) {
logger.warn("ProcessInstanceIdContext or CorrelationKeyContext shall be used when interacting with PerProcessInstance runtime manager");
}
if (engineInitEager) {
KieSession ksession = null;
Long ksessionId = null;
if (contextId == null || context instanceof EmptyContext) {
ksession = factory.newKieSession();
ksessionId = ksession.getIdentifier();
} else {
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
ksessionId = mapper.findMapping(context, this.identifier);
if (ksessionId == null) {
throw new SessionNotFoundException("No session found for context " + context.getContextId());
}
ksession = factory.findKieSessionById(ksessionId);
}
InternalTaskService internalTaskService = newTaskService(taskServiceFactory);
runtime = new RuntimeEngineImpl(ksession, internalTaskService);
((RuntimeEngineImpl) runtime).setManager(this);
((RuntimeEngineImpl) runtime).setContext(context);
configureRuntimeOnTaskService(internalTaskService, runtime);
registerDisposeCallback(runtime, new DisposeSessionTransactionSynchronization(this, runtime), ksession.getEnvironment());
registerItems(runtime);
attachManager(runtime);
ksession.addEventListener(new MaintainMappingListener(ksessionId, runtime, this.identifier));
} else {
RuntimeEngine localRuntime = findLocalRuntime(contextId);
if (localRuntime != null) {
return localRuntime;
}
// lazy initialization of ksession and task service
runtime = new RuntimeEngineImpl(context, new PerProcessInstanceInitializer());
((RuntimeEngineImpl) runtime).setManager(this);
}
createLockOnGetEngine(context, runtime);
saveLocalRuntime(contextId, runtime);
return runtime;
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class SubProcessNodeInstance method cancel.
public void cancel() {
super.cancel();
if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) {
ProcessInstance processInstance = null;
InternalKnowledgeRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime();
RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
if (manager != null) {
try {
org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(processInstanceId);
String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID);
if (caseId != null) {
context = CaseContext.get(caseId);
}
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession();
processInstance = (ProcessInstance) managedkruntime.getProcessInstance(processInstanceId);
} catch (SessionNotFoundException e) {
// in case no session is found for parent process let's skip signal for process instance completion
}
} else {
processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId);
}
if (processInstance != null) {
processInstance.setState(ProcessInstance.STATE_ABORTED);
}
}
}
Aggregations