use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireAfterVariableChanged.
public void fireAfterVariableChanged(final String name, final String id, final Object oldValue, final Object newValue, final List<String> tags, final ProcessInstance processInstance, NodeInstance nodeInstance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessVariableChangedEvent event = new ProcessVariableChangedEventImpl(name, id, oldValue, newValue, tags, processInstance, nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.afterVariableChanged(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.afterVariableChanged(e));
}));
}
use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireBeforeSLAViolated.
public void fireBeforeSLAViolated(final ProcessInstance instance, NodeInstance nodeInstance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final SLAViolatedEvent event = new SLAViolatedEventImpl(instance, nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.beforeSLAViolated(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.beforeSLAViolated(e));
}));
}
use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireBeforeNodeLeft.
public void fireBeforeNodeLeft(final NodeInstance nodeInstance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessNodeLeftEvent event = new ProcessNodeLeftEventImpl(nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.beforeNodeLeft(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.beforeNodeLeft(e));
}));
}
use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.
the class JoinInstance method existsActiveDirectFlow.
private boolean existsActiveDirectFlow(NodeInstanceContainer nodeInstanceContainer, final Node lookFor) {
Collection<NodeInstance> activeNodeInstancesOrig = nodeInstanceContainer.getNodeInstances();
List<NodeInstance> activeNodeInstances = new ArrayList<NodeInstance>(activeNodeInstancesOrig);
// sort active instances in the way that lookFor nodeInstance will be last to
// not finish too early
Collections.sort(activeNodeInstances, new Comparator<NodeInstance>() {
@Override
public int compare(NodeInstance o1, NodeInstance o2) {
if (o1.getNodeId() == lookFor.getId()) {
return 1;
} else if (o2.getNodeId() == lookFor.getId()) {
return -1;
}
return 0;
}
});
for (NodeInstance nodeInstance : activeNodeInstances) {
// black box
if (((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).getLevel() != getLevel()) {
continue;
}
Node node = nodeInstance.getNode();
Set<Long> vistedNodes = new HashSet<Long>();
checkNodes(vistedNodes, node, node, lookFor);
if (vistedNodes.contains(lookFor.getId()) && !vistedNodes.contains(node.getId())) {
return true;
}
}
return false;
}
use of io.automatiko.engine.api.runtime.process.NodeInstance 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