4 Replies Latest reply on Dec 9, 2014 3:29 AM by Maciej Swiderski

    [JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?

    Mateusz Adamiak Newbie

      Hi,

       

      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.

       

      [1] - Chapter 24. Concurrency and asynchronous execution

        • 1. Re: [JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?
          Maciej Swiderski Master

          most likely there is an exception while reading a .conf file so both handlers are not registered so either check logs or try to debug it to see why it does fail when initializing the handler. It is certainly a supported feature.

           

          HTH

          • 2. Re: Re: [JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?
            Mateusz Adamiak Newbie

            I think the exception below is the cause, but it tells me nothing.

             

            12:19:10,385 WARN  (com.arjuna.ats.jta) [10.41.106.32:9443-2] ARJUNA016029: SynchronizationImple.afterCompletion - failed for org.drools.persistence.jta.JtaTransactionSynchronizationAdapter@3ce96b59 with exception: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
                    at java.lang.String.substring(String.java:1949) [rt.jar:1.6.0_24]
                    at java.lang.String.substring(String.java:1916) [rt.jar:1.6.0_24]
                    at org.mvel2.util.ErrorUtil.rewriteIfNeeded(ErrorUtil.java:12) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:167) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVEL.eval(MVEL.java:150) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.ast.InlineCollectionNode.execGraph(InlineCollectionNode.java:180) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.ast.InlineCollectionNode.execGraph(InlineCollectionNode.java:138) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.ast.InlineCollectionNode.getReducedValue(InlineCollectionNode.java:105) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVELInterpretedRuntime.parseAndExecuteInterpreted(MVELInterpretedRuntime.java:106) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVELInterpretedRuntime.parse(MVELInterpretedRuntime.java:49) [mvel2-2.1.3.Final.jar:]
                    at org.mvel2.MVEL.eval(MVEL.java:165) [mvel2-2.1.3.Final.jar:]
                    at org.drools.SessionConfiguration.loadWorkItemHandlers(SessionConfiguration.java:311) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.SessionConfiguration.initWorkItemHandlers(SessionConfiguration.java:301) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.SessionConfiguration.getWorkItemHandlers(SessionConfiguration.java:276) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.common.AbstractWorkingMemory.getWorkItemManager(AbstractWorkingMemory.java:1106) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.impl.StatefulKnowledgeSessionImpl.getWorkItemManager(StatefulKnowledgeSessionImpl.java:309) [drools-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.persistence.SingleSessionCommandService$SynchronizationImpl.afterCompletion(SingleSessionCommandService.java:439) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.persistence.jta.JtaTransactionSynchronizationAdapter.afterCompletion(JtaTransactionSynchronizationAdapter.java:22) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.afterCompletion(SynchronizationImple.java:96)
                    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:402)
                    at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:103)
                    at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
                    at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
                    at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
                    at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
                    at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:167)
                    at org.drools.persistence.jta.JtaTransactionManager.commit(JtaTransactionManager.java:179) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:194) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_24]
                    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.6.0_24]
                    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.6.0_24]
                    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) [rt.jar:1.6.0_24]
                    at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:99) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.loadStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:82) [drools-persistence-jpa-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.drools.persistence.jpa.JPAKnowledgeService.loadStatefulKnowledgeSession(JPAKnowledgeService.java:131) [knowledge-api-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.StatefulKnowledgeSessionUtil.createOrLoadStatefulKnowledgeSession(StatefulKnowledgeSessionUtil.java:288) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.StatefulKnowledgeSessionUtil.initializeStatefulKnowledgeSession(StatefulKnowledgeSessionUtil.java:159) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.StatefulKnowledgeSessionUtil$SessionHolder.<clinit>(StatefulKnowledgeSessionUtil.java:132) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession(StatefulKnowledgeSessionUtil.java:136) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.SessionInitializer.<init>(SessionInitializer.java:25) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.ProcessManagement.<init>(ProcessManagement.java:38) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.ManagementFactory.createProcessManagement(ManagementFactory.java:22) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jbpm.integration.console.ManagementFactory.createProcessManagement(ManagementFactory.java:19) [jbpm-gwt-core-5.3.1.BRMS.jar:5.3.1.BRMS]
                    at org.jboss.bpm.console.server.ProcessMgmtFacade.getProcessManagement(ProcessMgmtFacade.java:89) [classes:]
                    at org.jboss.bpm.console.server.ProcessMgmtFacade.getDefinitionsJSON(ProcessMgmtFacade.java:125) [classes:]
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_24]
                    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.6.0_24]
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.6.0_24]
                    at java.lang.reflect.Method.invoke(Method.java:616) [rt.jar:1.6.0_24]
                    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:269) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:227) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:216) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:542) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
                    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.jboss.bpm.console.server.util.GWTJsonFilter.doFilter(GWTJsonFilter.java:59) [classes:]
                    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.java:91)
                    at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.java:72)
                    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:499) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.3.2.Final-redhat-2.jar:7.3.2.Final-redhat-2]
                    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.3.2.Final-redhat-2.jar:7.3.2.Final-redhat-2]
                    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.3.2.Final-redhat-2.jar:7.3.2.Final-redhat-2]
                    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.3.1.Final-redhat-1.jar:7.3.1.Final-redhat-1]
                    at java.lang.Thread.run(Thread.java:679) [rt.jar:1.6.0_24]
            
            
            

             

            All I can say is that there is some problem with parsing this *.conf file (as you said) which is in MVEL format. The problem here is giving ksession as parameter aparently, but how can I do it otherwise?

            • 3. Re: Re: [JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?
              Mateusz Adamiak Newbie

              In jBPM used in BRMS 5.3 the implementation does not support injecting ksession in MVEL file I think, because when I debugged parsing my file through MVEL parser it thrown exception that it does not know what ksession is. Then I put into the HashMap ksession as a key and it worked. But in the implementation always new HashMap() is passed, so, as far as I understand, there is no way to put ksession into the constructor of work item handler in this version. Am I right?

               

              If so, how can I get the ksession (KnowledgeStatefulSession) in some other way?

               

              I attach the interesting part of Drools implementation used in jBPM (SessionConfiguration class)

              private void loadWorkItemHandlers(String location) {
                  String content = ConfFileUtils.URLContentsToString(ConfFileUtils.getURL(location, (ClassLoader)null, RuleBaseConfiguration.class));
                  Map workItemHandlers = (Map)MVEL.eval(content, new HashMap());
                  this.workItemHandlers.putAll(workItemHandlers);
              }
              

              where content is the configuration file.

              • 4. Re: [JBoss BRMS 5.3][jBPM 5.2] How to provide ksession into work item handler?
                Maciej Swiderski Master

                this is certainly supported in brms 5.3 just make sure you run on latest version/patch

                 

                HTH