use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class NodeInstanceImpl method triggerCompleted.
protected void triggerCompleted(String type, boolean remove) {
getExecutionErrorHandler().processed(this);
Node node = getNode();
if (node != null) {
String uniqueId = (String) node.getMetaData().get("UniqueId");
if (uniqueId == null) {
uniqueId = ((NodeImpl) node).getUniqueId();
}
((WorkflowProcessInstanceImpl) processInstance).addCompletedNodeId(uniqueId);
((WorkflowProcessInstanceImpl) processInstance).getIterationLevels().remove(uniqueId);
}
// if node instance was cancelled, or containing container instance was cancelled
if ((getNodeInstanceContainer().getNodeInstance(getId()) == null) || (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE)) {
return;
}
if (remove) {
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
}
List<Connection> connections = null;
if (node != null) {
if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
int priority = Integer.MAX_VALUE;
connections = ((NodeImpl) node).getDefaultOutgoingConnections();
boolean found = false;
List<NodeInstanceTrigger> nodeInstances = new ArrayList<NodeInstanceTrigger>();
List<Connection> outgoingCopy = new ArrayList<Connection>(connections);
while (!outgoingCopy.isEmpty()) {
priority = Integer.MAX_VALUE;
Connection selectedConnection = null;
ConstraintEvaluator selectedConstraint = null;
for (final Iterator<Connection> iterator = outgoingCopy.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
priority = constraint.getPriority();
selectedConnection = connection;
selectedConstraint = constraint;
}
}
if (selectedConstraint == null) {
break;
}
if (selectedConstraint.evaluate(this, selectedConnection, selectedConstraint)) {
nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType()));
found = true;
}
outgoingCopy.remove(selectedConnection);
}
for (NodeInstanceTrigger nodeInstance : nodeInstances) {
// stop if this process instance has been aborted / completed
if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
}
if (!found) {
for (final Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint.isDefault()) {
triggerConnection(connection);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalArgumentException("Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName());
}
return;
} else {
connections = node.getOutgoingConnections(type);
}
}
if (connections == null || connections.isEmpty()) {
boolean hidden = false;
Node currentNode = getNode();
if (currentNode != null && currentNode.getMetaData().get("hidden") != null) {
hidden = true;
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
}
// notify container
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
} else {
Map<org.jbpm.workflow.instance.NodeInstance, String> nodeInstances = new HashMap<org.jbpm.workflow.instance.NodeInstance, String>();
for (Connection connection : connections) {
nodeInstances.put(followConnection(connection), connection.getToType());
}
for (Map.Entry<org.jbpm.workflow.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
// stop if this process instance has been aborted / completed
if (((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
}
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategy method retrieveKnowledgeRuntime.
/**
* Retrieve the {@link ProcessInstanceManager} object from the ObjectOutput- or ObjectInputStream.
* The stream object will secretly also either be a {@link MarshallerReaderContext} or a
* {@link MarshallerWriteContext}.
* </p>
* The knowledge runtime object is useful in order to reconnect the process instance to the
* process and the knowledge runtime object.
* @param streamContext The marshaller stream/context.
* @return A {@link InternalKnowledgeRuntime} object.
*/
public static InternalKnowledgeRuntime retrieveKnowledgeRuntime(Object streamContext) {
InternalKnowledgeRuntime kruntime = null;
if (streamContext instanceof MarshallerWriteContext) {
MarshallerWriteContext context = (MarshallerWriteContext) streamContext;
kruntime = ((InternalWorkingMemory) context.wm).getKnowledgeRuntime();
} else if (streamContext instanceof MarshallerReaderContext) {
MarshallerReaderContext context = (MarshallerReaderContext) streamContext;
kruntime = ((InternalWorkingMemory) context.wm).getKnowledgeRuntime();
} else {
throw new UnsupportedOperationException("Unable to retrieve " + ProcessInstanceManager.class.getSimpleName() + " from " + streamContext.getClass().getName());
}
return kruntime;
}
use of org.drools.core.common.InternalKnowledgeRuntime in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategy method connectProcessInstanceToRuntimeAndProcess.
/**
* Fill the process instance .kruntime and .process fields with the appropriate values.
* @param processInstance
* @param streamContext
*/
private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance, Object streamContext) {
ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance;
InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime();
// Attach the kruntime if not present
if (kruntime == null) {
kruntime = retrieveKnowledgeRuntime(streamContext);
processInstanceImpl.setKnowledgeRuntime(kruntime);
}
// Attach the process if not present
if (processInstance.getProcess() == null) {
String processId = processInstance.getProcessId();
if (processId != null) {
Process process = kruntime.getKieBase().getProcess(processId);
if (process != null) {
processInstanceImpl.setProcess(process);
}
}
}
}
use of org.drools.core.common.InternalKnowledgeRuntime in project drools by kiegroup.
the class PersistableRunner method initExistingKnowledgeSession.
protected void initExistingKnowledgeSession(Long sessionId, KieBase kbase, KieSessionConfiguration conf, PersistenceContext persistenceContext) {
if (!doRollback && this.ksession != null) {
return;
// nothing to initialise
}
this.doRollback = false;
try {
// if locking is active, this will also lock the (found) SessionInfo instance
this.sessionInfo = (SessionInfo) persistenceContext.findSession(sessionId);
} catch (Exception e) {
throw new SessionNotFoundException("Could not find session data for id " + sessionId, e);
}
if (sessionInfo == null) {
throw new SessionNotFoundException("Could not find session data for id " + sessionId);
}
if (this.marshallingHelper == null) {
// this should only happen when this class is first constructed
this.marshallingHelper = new SessionMarshallingHelper(kbase, conf, env);
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances(false);
config.setMarshallWorkItems(false);
}
this.sessionInfo.setJPASessionMashallingHelper(this.marshallingHelper);
// if this.ksession is null, it'll create a new one, else it'll use the existing one
this.ksession = this.marshallingHelper.loadSnapshot(this.sessionInfo.getData(), this.ksession, new JpaSessionInitializer(this));
// update the session id to be the same as the session info id
InternalKnowledgeRuntime kruntime = ((InternalKnowledgeRuntime) ksession);
kruntime.setIdentifier(this.sessionInfo.getId());
kruntime.setEndOperationListener(new EndOperationListenerImpl(this.txm, this.sessionInfo));
this.runner = new TransactionInterceptor();
// apply interceptors
Iterator<ChainableRunner> iterator = this.interceptors.descendingIterator();
while (iterator.hasNext()) {
addInterceptor(iterator.next(), false);
}
initKieSessionMBeans(this.ksession);
}
use of org.drools.core.common.InternalKnowledgeRuntime in project drools by kiegroup.
the class PersistableRunner method initNewKnowledgeSession.
protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration conf) {
this.sessionInfo = new SessionInfo();
// create session but bypass command service
this.ksession = kbase.newKieSession(conf, this.env);
initKieSessionMBeans(this.ksession);
this.marshallingHelper = new SessionMarshallingHelper(this.ksession, conf);
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances(false);
config.setMarshallWorkItems(false);
this.sessionInfo.setJPASessionMashallingHelper(this.marshallingHelper);
((InternalKnowledgeRuntime) this.ksession).setEndOperationListener(new EndOperationListenerImpl(this.txm, this.sessionInfo));
this.runner = new TransactionInterceptor();
TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession).getTimerService().getTimerJobFactoryManager();
if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) {
((CommandServiceTimerJobFactoryManager) timerJobFactoryManager).setRunner(this);
}
}
Aggregations