Hi,
I am working on a flow that uses flow events.
I send the event from a rule, and the only way I know to send an event
requires that I know the processId as well as the sessionId. Which
means I need to be able to keep track of both those two values so that
I can later use them to send the event.
So the question is what is the best strategy to keep track of the
sessions and the processes ?
The following is what I do; please comment on it, and feel free to
suggest a better way.
I ve created a class called WorkflowInfo that has two members (
processId, and sessionId )
When I start the process I create a WorkflowInfo, I set the processId,
and the sessionId then I insert it into the working memory:
WorkflowInfo info = new WorkflowInfo();
info.setProcessId(instance.getId());
info.setSessionId(ksession.getId());
ksession.insert(info);
In one of the rules I check for a condition, and when it is met I send
the flow event:
rule "sendEvent"
when
$info : WorkflowInfo()
<something is true>
then
DroolsEventsManager.getInstance().sendEvent($info.getProcessId(),
$info.getSessionId(), "someEvent");
end
Now to send the event this is what I do ( from a java class ):
public void sendEvent(long processId, int sessionId, String eventType)
{
StatefulKnowledgeSession session =
JPAKnowledgeSessionLookup.getInstance().loadSession(sessionId);
try {
SignalEventCommand command = new SignalEventCommand();
command.setProcessInstanceId(processId);
command.setEventType(eventType);
command.setEvent(true);
session.execute(command);
} catch (Exception e) {
Logger.getInstance().error(this.getClass(), e.getMessage());
e.printStackTrace();
}
finally{
session.dispose();
}
}
Does this approach make sense ?
Thanks