[rules-users] Drools Flow: how to get knowledge session ID from WorkItem

Chris Raschl c.raschl-mailinglists at dyless.com
Tue May 4 07:29:54 EDT 2010


Hi Alan,

On 2010-05-04 13:10, Alan.Gairey at tessella.com wrote:
> The subject says it all really: is there any way of determining the
> knowledge session ID from the WorkItem argument (or WorkItemManager
> argument?) passed in to the executeWorkItem method of an implementation
> of the WorkItemHandler interface?

I had the same problem so i simply extended the work item handler interface like this:

public interface SessionAwareWorkItemHandler extends WorkItemHandler {
	
	StatefulKnowledgeSession getKnowledgeSession();
	void setKnowledgeSession(StatefulKnowledgeSession session);
}

If you register a SessionAwareWorkItemHandler, just let him know about the session:

if (handler instanceof SessionAwareWorkItemHandler) {
	SessionAwareWorkItemHandler sessionAware = (SessionAwareWorkItemHandler)handler;
	sessionAware.setKnowledgeSession(ksession);
}

ksession.getWorkItemManager().registerWorkItemHandler("workItem", handler);

Hope this helps, it works for me.

- chris




More information about the rules-users mailing list