StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
CompositeNode compositeNode = new CompositeNode();
compositeNode.setName("CompositeNode");
compositeNode.setId(2);
process.addNode(compositeNode);
new ConnectionImpl(
startNode, Node.CONNECTION_DEFAULT_TYPE,
compositeNode, Node.CONNECTION_DEFAULT_TYPE
);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
compositeNode.addNode(milestoneNode);
compositeNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, milestoneNode.getId(), Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
compositeNode.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory, ProcessContext context) throws Exception {
System.out.println("Detected event for person " + ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
compositeNode.addNode(actionNode);
new ConnectionImpl(
eventNode, Node.CONNECTION_DEFAULT_TYPE,
actionNode, Node.CONNECTION_DEFAULT_TYPE
);
Join join = new Join();
join.setName("XOR Join");
join.setType(Join.TYPE_XOR);
compositeNode.addNode(join);
new ConnectionImpl(
milestoneNode, Node.CONNECTION_DEFAULT_TYPE,
join, Node.CONNECTION_DEFAULT_TYPE
);
new ConnectionImpl(
actionNode, Node.CONNECTION_DEFAULT_TYPE,
join, Node.CONNECTION_DEFAULT_TYPE
);
compositeNode.linkOutgoingConnections(join.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(3);
process.addNode(endNode);