use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class CompensationScopeInstance method handleException.
public void handleException(ExceptionHandler handler, String compensationActivityRef, Object dunno) {
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) getProcessInstance();
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getContextInstanceContainer();
if (handler instanceof CompensationHandler) {
CompensationHandler compensationHandler = (CompensationHandler) handler;
try {
Node handlerNode = compensationHandler.getnode();
if (handlerNode instanceof BoundaryEventNode) {
NodeInstance compensationHandlerNodeInstance = nodeInstanceContainer.getNodeInstance(handlerNode);
compensationInstances.add(compensationHandlerNodeInstance);
// The BoundaryEventNodeInstance.signalEvent() contains the necessary logic
// to check whether or not compensation may proceed (? : (not-active + completed))
EventNodeInstance eventNodeInstance = (EventNodeInstance) compensationHandlerNodeInstance;
eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
} else if (handlerNode instanceof EventSubProcessNode) {
// Check that subprocess parent has completed.
List<String> completedIds = processInstance.getCompletedNodeIds();
if (completedIds.contains(((NodeImpl) handlerNode.getNodeContainer()).getMetaData("UniqueId"))) {
NodeInstance subProcessNodeInstance = ((NodeInstanceContainer) nodeInstanceContainer).getNodeInstance((Node) handlerNode.getNodeContainer());
compensationInstances.add(subProcessNodeInstance);
NodeInstance compensationHandlerNodeInstance = ((NodeInstanceContainer) subProcessNodeInstance).getNodeInstance(handlerNode);
compensationInstances.add(compensationHandlerNodeInstance);
EventSubProcessNodeInstance eventNodeInstance = (EventSubProcessNodeInstance) compensationHandlerNodeInstance;
eventNodeInstance.signalEvent("Compensation", compensationActivityRef);
}
}
assert handlerNode instanceof BoundaryEventNode || handlerNode instanceof EventSubProcessNode : "Unexpected compensation handler node type : " + handlerNode.getClass().getSimpleName();
} catch (Exception e) {
throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, "Unable to execute compensation.", e);
}
} else {
Exception e = new IllegalArgumentException("Unsupported compensation handler: " + handler);
throwWorkflowRuntimeException(nodeInstanceContainer, processInstance, e.getMessage(), e);
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class CompensationScopeInstance method handleException.
public void handleException(String activityRef, Object dunno) {
assert activityRef != null : "It should not be possible for the compensation activity reference to be null here.";
CompensationScope compensationScope = (CompensationScope) getExceptionScope();
// broadcast/general compensation in reverse order
if (activityRef.startsWith(IMPLICIT_COMPENSATION_PREFIX)) {
activityRef = activityRef.substring(IMPLICIT_COMPENSATION_PREFIX.length());
assert activityRef.equals(compensationScope.getContextContainerId()) : "Compensation activity ref [" + activityRef + "] does not match" + " Compensation Scope container id [" + compensationScope.getContextContainerId() + "]";
Map<String, ExceptionHandler> handlers = compensationScope.getExceptionHandlers();
List<String> completedNodeIds = ((WorkflowProcessInstanceImpl) getProcessInstance()).getCompletedNodeIds();
ListIterator<String> iter = completedNodeIds.listIterator(completedNodeIds.size());
while (iter.hasPrevious()) {
String completedId = iter.previous();
ExceptionHandler handler = handlers.get(completedId);
if (handler != null) {
handleException(handler, completedId, null);
}
}
} else {
// Specific compensation
ExceptionHandler handler = compensationScope.getExceptionHandler(activityRef);
if (handler == null) {
throw new IllegalArgumentException("Could not find CompensationHandler for " + activityRef);
}
handleException(handler, activityRef, null);
}
// Cancel all node instances created for compensation
while (!compensationInstances.isEmpty()) {
NodeInstance generatedInstance = compensationInstances.pop();
((NodeInstanceContainer) generatedInstance.getNodeInstanceContainer()).removeNodeInstance(generatedInstance);
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class StateNodeInstance method activationCreated.
public void activationCreated(MatchCreatedEvent event) {
Connection selected = null;
for (Connection connection : getNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
Constraint constraint = getStateNode().getConstraint(connection);
if (constraint != null) {
String constraintName = getActivationEventType() + "-" + connection.getTo().getId() + "-" + connection.getToType();
if (constraintName.equals(event.getMatch().getRule().getName()) && checkProcessInstance((Activation) event.getMatch())) {
selected = connection;
}
}
}
if (selected != null) {
removeEventListeners();
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
triggerConnection(selected);
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class StateNodeInstance method internalTrigger.
public void internalTrigger(NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
// TODO: composite states trigger
StateNode stateNode = getStateNode();
Connection selected = null;
int priority = Integer.MAX_VALUE;
for (Connection connection : stateNode.getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
Constraint constraint = stateNode.getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority) {
String rule = "RuleFlowStateNode-" + getProcessInstance().getProcessId() + "-" + getStateNode().getUniqueId() + "-" + connection.getTo().getId() + "-" + connection.getToType();
boolean isActive = ((InternalAgenda) getProcessInstance().getKnowledgeRuntime().getAgenda()).isRuleActiveInRuleFlowGroup("DROOLS_SYSTEM", rule, getProcessInstance().getId());
if (isActive) {
selected = connection;
priority = constraint.getPriority();
}
}
}
if (selected != null) {
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
triggerConnection(selected);
} else {
addTriggerListener();
addActivationListener();
}
}
use of org.jbpm.workflow.instance.NodeInstanceContainer in project jbpm by kiegroup.
the class EndNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
if (getEndNode().isTerminate()) {
if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
if (getEndNode().getScope() == EndNode.PROCESS_SCOPE) {
getProcessInstance().setState(ProcessInstance.STATE_COMPLETED);
} else {
while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
((org.jbpm.workflow.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_COMPLETED);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
}
Aggregations