use of io.automatiko.engine.api.event.process.ProcessEventListener in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireAfterNodeInstanceFailed.
public void fireAfterNodeInstanceFailed(final ProcessInstance instance, NodeInstance nodeInstance, String errorId, String errorMessage, Exception exception, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessNodeInstanceFailedEvent event = new ProcessNodeInstanceFailedEventImpl(instance, nodeInstance, errorId, errorMessage, exception, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.afterNodeInstanceFailed(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
delayedListeners.forEach(l -> l.afterNodeInstanceFailed(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessEventListener in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireAfterNodeTriggered.
public void fireAfterNodeTriggered(final NodeInstance nodeInstance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final ProcessNodeTriggeredEvent event = new ProcessNodeTriggeredEventImpl(nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.afterNodeTriggered(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.afterNodeTriggered(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessEventListener in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireBeforeVariableChanged.
public void fireBeforeVariableChanged(final String id, final String instanceId, 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(id, instanceId, oldValue, newValue, tags, processInstance, nodeInstance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.beforeVariableChanged(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.beforeVariableChanged(e));
}));
}
use of io.automatiko.engine.api.event.process.ProcessEventListener in project automatiko-engine by automatiko-io.
the class ProcessEventSupportTest method testProcessEventListener.
@Test
public void testProcessEventListener() throws Exception {
// create a simple package with one process to test the events
ExecutableProcess process = new ExecutableProcess();
process.setId("org.company.core.process.event");
process.setName("Event Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
ProcessAction action = new ConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(2);
process.addNode(actionNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
process.addNode(endNode);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
final ProcessEventListener processEventListener = new ProcessEventListener() {
public void afterNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void afterProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void afterProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void beforeProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void beforeProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
};
processRuntime.addEventListener(processEventListener);
// execute the process
processRuntime.startProcess("org.company.core.process.event");
assertEquals(16, processEventList.size());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(7)).getProcessInstance().getProcessId());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(8)).getProcessInstance().getProcessId());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(13)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(14)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
}
use of io.automatiko.engine.api.event.process.ProcessEventListener in project automatiko-engine by automatiko-io.
the class ProcessEventSupportTest method testProcessEventListenerWithEndEvent.
@Test
public void testProcessEventListenerWithEndEvent() throws Exception {
ExecutableProcess process = new ExecutableProcess();
process.setId("org.company.core.process.event");
process.setName("Event Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
ProcessAction action = new ConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(2);
process.addNode(actionNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
endNode.setTerminate(false);
process.addNode(endNode);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
final ProcessEventListener processEventListener = new ProcessEventListener() {
public void afterNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void afterProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void afterProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void beforeProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void beforeProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
};
processRuntime.addEventListener(processEventListener);
// execute the process
processRuntime.startProcess("org.company.core.process.event");
assertEquals(14, processEventList.size());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(7)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(8)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(13)).getProcessInstance().getProcessId());
}
Aggregations