use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.
the class CompositeNodeInstance method internalTrigger.
@Override
public void internalTrigger(final io.automatiko.engine.api.runtime.process.NodeInstance from, String type) {
super.internalTrigger(from, type);
// if node instance was cancelled, abort
if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
return;
}
CompositeNode.NodeAndType nodeAndType = getCompositeNode().internalGetLinkedIncomingNode(type);
if (nodeAndType != null) {
List<Connection> connections = nodeAndType.getNode().getIncomingConnections(nodeAndType.getType());
for (Connection connection : connections) {
if ((connection.getFrom() instanceof CompositeNode.CompositeNodeStart) && (from == null || ((CompositeNode.CompositeNodeStart) connection.getFrom()).getInNode().getId() == from.getNodeId())) {
NodeInstance nodeInstance = getNodeInstance(connection.getFrom());
nodeInstance.trigger(null, nodeAndType.getType());
return;
}
}
} else {
// try to search for start nodes
boolean found = false;
for (Node node : getCompositeNode().getNodes()) {
if (node instanceof StartNode) {
StartNode startNode = (StartNode) node;
if (startNode.getTriggers() == null || startNode.getTriggers().isEmpty()) {
NodeInstance nodeInstance = getNodeInstance(startNode);
nodeInstance.trigger(null, null);
found = true;
}
}
}
if (found) {
return;
}
}
if (isLinkedIncomingNodeRequired()) {
throw new IllegalArgumentException("Could not find start for composite node: " + type);
}
}
use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.
the class StateNodeInstance method signalEvent.
public void signalEvent(String type, Object event) {
if ("signal".equals(type)) {
if (event instanceof String) {
for (Connection connection : getStateNode().getOutgoingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE)) {
boolean selected = false;
Constraint constraint = getStateNode().getConstraint(connection);
if (constraint == null) {
if (((String) event).equals(connection.getTo().getName())) {
selected = true;
}
} else if (((String) event).equals(constraint.getName())) {
selected = true;
}
if (selected) {
triggerEvent(ExtendedNodeImpl.EVENT_NODE_EXIT);
removeEventListeners();
((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
triggerConnection(connection);
return;
}
}
}
} else if ("variableChanged".equals(type)) {
if (isCompleted()) {
triggerCompleted();
}
} else {
super.signalEvent(type, event);
}
}
use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method triggerNodeInstance.
protected void triggerNodeInstance(io.automatiko.engine.workflow.process.instance.NodeInstance nodeInstance, String type, boolean fireEvents) {
if (nodeInstance == null) {
return;
}
leaveTime = new Date();
boolean hidden = false;
if (getNode().getMetaData().get(HIDDEN) != null) {
hidden = true;
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
if (!hidden && fireEvents) {
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
// trigger next node
nodeInstance.trigger(this, type);
Collection<Connection> outgoing = getNode().getOutgoingConnections(type);
for (Connection conn : outgoing) {
if (conn.getTo().getId() == nodeInstance.getNodeId()) {
this.metaData.put(OUTGOING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
break;
}
}
if (!hidden && fireEvents) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
}
use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method retry.
public void retry() {
boolean hidden = false;
if (getNode().getMetaData().get(HIDDEN) != null) {
hidden = true;
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
try {
internalChangeState(NodeInstanceState.Active);
internalTrigger(this, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
Collection<Connection> outgoing = getNode().getOutgoingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
for (Connection conn : outgoing) {
if (conn.getTo().getId() == getNodeId()) {
this.metaData.put(OUTGOING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
break;
}
}
if (!hidden) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} catch (Exception e) {
String errorId = captureError(e);
internalChangeState(NodeInstanceState.Failed);
runtime.getProcessEventSupport().fireAfterNodeInstanceFailed(getProcessInstance(), this, errorId, getRootException(e).getMessage(), e, runtime);
// stop after capturing error
return;
}
}
use of io.automatiko.engine.api.definition.process.Connection in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method continueToNextNode.
protected void continueToNextNode(String type, Node node) {
List<Connection> connections = null;
if (node != null) {
if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
int priority;
connections = ((NodeImpl) node).getDefaultOutgoingConnections();
boolean found = false;
List<NodeInstanceTrigger> nodeInstances = new ArrayList<>();
List<Connection> outgoingCopy = new ArrayList<>(connections);
while (!outgoingCopy.isEmpty()) {
priority = Integer.MAX_VALUE;
Connection selectedConnection = null;
ConstraintEvaluator selectedConstraint = null;
for (final Connection connection : outgoingCopy) {
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 (((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
}
if (!found) {
for (final Connection connection : connections) {
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;
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
if (!hidden) {
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
// notify container
((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
if (!hidden) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} else {
Map<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstances = new HashMap<>();
for (Connection connection : connections) {
nodeInstances.put(followConnection(connection), connection.getToType());
}
for (Map.Entry<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
// stop if this process instance has been aborted / completed
int state = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState();
if (state == STATE_COMPLETED || state == STATE_ABORTED) {
return;
}
try {
triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
} catch (Exception e) {
logger.warn("Error caught at executing node instance " + nodeInstance.getKey(), e);
}
}
}
}
Aggregations