Just need to add a ProcesEventListener() to the ksession.
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
CustomProcessEventListener customProcessEventListener = new CustomProcessEventListener();
ksession.addEventListener(customProcessEventListener);
...
...
ksession.startProcess("com.sample.MyTaskFlow", params);
And here is the sample CustomProcessEventListener();
private static class CustomProcessEventListener implements ProcessEventListener {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
// TODO Auto-generated method stub
logger.debug("Process has completed.");
System.exit(0);
}
@Override
public void afterProcessStarted(ProcessStartedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
// TODO Auto-generated method stub
logger.debug("Process is going to be completed.");
}
@Override
public void beforeProcessStarted(ProcessStartedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
// TODO Auto-generated method stub
}
}
As you can see, you can do many things on every stage of a process.
No comments:
Post a Comment