[JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?
mateuszadamiak Nov 6, 2014 8:27 AMHi,
I am working on async service task, but it does not work so far. In [1] there is code snippet for asynchronous handler execution that I used for my AsyncWorkItemHandler, which looks like this:
public class AsyncWorkItemHandler implements WorkItemHandler { private final StatefulKnowledgeSession ksession; public AsyncWorkItemHandler( StatefulKnowledgeSession ksession ) { this.ksession = ksession; } @Override public void abortWorkItem( WorkItem workItem, final WorkItemManager workItemManager ) { workItemManager.abortWorkItem(workItem.getId()); } @Override public void executeWorkItem( final WorkItem workItem, WorkItemManager workItemManager ) { new Thread( new Runnable() { public void run() { try { System.out.println( "=== Async service task started ===" ); Thread.sleep( 10000 ); System.out.println( "=== Async service task ended ===" ); System.out.println( "=== Completing work item with id " + workItem.getId() + " ===" ); ksession.getWorkItemManager().completeWorkItem( workItem.getId(), null ); // workItemManager.completeWorkItem( workItem.getId(), null ); System.out.println( "=== Completed work item with id " + workItem.getId() + " ===" ); } catch( InterruptedException e ) { e.printStackTrace(); } } } ).start(); } }
Unfortunately I cannot provide the ksession object in CustomWorkItemHandlers.conf, because then during the process execution I get "Could not find work item handler for Async". When I specify only the default constructor for AsyncWorkItemHandler and in CustomWorkItemHandlers.conf there is no ksession as an argument, the handler is found.
[ "First" : new com.example.CustomWorkItemHandler(), "Async" : new com.example.AsyncWorkItemHandler(ksession) // does not work //"Async" : new com.example.AsyncWorkItemHandler() // works ]
What's interesting is also the fact, that when AsyncWorkItemHandler gets ksession in constructor, both Async and First tasks cannot be found. When Async has no arguments in constructor, both are executable.
Can someone help me with this? How can I provide ksession into work item handler, so I can invoke asynchronous task?
Thanks,
Mateusz.