5 Replies Latest reply on Apr 30, 2013 12:53 AM by roxy1987

    Problems with Local Task Service

    roxy1987

      Guys,

       

      I have a process with 2 tasks. I am using local task service. The process starts fine and completion of 1st task is also clean. but the 2nd task is not assigned. neither it is listed in the database. What could be the reason?

       

      Following is my code for initiate process and complete task.

       

      Initiate :

       

      StatefulKnowledgeSession ksession;
        long processInstanceId = -1;
        try
        {
         ksession = BpmRepositoryConfig.createSession(processName);
         KnowledgeRuntimeLogger logger1 = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "testlog", 1000);
         LocalHTWorkItemHandler handler = new LocalHTWorkItemHandler(ksession);
         org.jbpm.task.service.TaskService service = BpmRepositoryConfig.getService();
         TaskService taService = BpmRepositoryConfig.getTaskService(ksession, service);
         handler.setClient(taService);
         ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
            JPAWorkingMemoryDbLogger logger2 = new JPAWorkingMemoryDbLogger(ksession);
              ProcessInstance prcInstance = ksession.startProcess(processDefId, mapParameters);
              processInstanceId = prcInstance.getId();
        }
        catch (Exception e)
        {
         e.printStackTrace();
        }
      
      

       

      Complete :

       

      StatefulKnowledgeSession ksession = BpmRepositoryConfig.createSession(processName);
        org.jbpm.task.service.TaskService tservice = BpmRepositoryConfig.getService(); 
        TaskService taskService = BpmRepositoryConfig.getTaskService(ksession,tservice);
        try
        {
         for(long task : taskId)
         {
          taskService.start(task, userId); 
          taskService.complete(task, userId, null);
         }
        }
        catch (Exception e)
        {
         e.printStackTrace();
        }
      
      

       

      Other methods :

       

       

       public static org.jbpm.task.service.TaskService getService()
       {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task");
        org.jbpm.task.service.TaskService tservice = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
        TaskServiceSession taskSession = tservice.createSession();   
              taskSession.addUser(new User("Administrator"));
              taskSession.addUser(new User("krisv")); 
              taskSession.addUser(new User("john"));
              taskSession.addUser(new User("mary"));
        return tservice;
       }
      
      
       public static  TaskService getTaskService(StatefulKnowledgeSession ksession,org.jbpm.task.service.TaskService taskService)
       {       
        TaskService client = new LocalTaskService(taskService);
              LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);
           ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);
           return client;  
          }
      
      

       

       

      Thanks.

        • 1. Re: Problems with Local Task Service
          roxy1987

          Any Help here please.

          • 2. Re: Problems with Local Task Service
            swiderski.maciej

            when you create new handler (LocalHTWorkItemHandler) you need to call connect on it to register event listeners so when task is completed ksession will be notified.

             

            HTH

            1 of 1 people found this helpful
            • 3. Re: Problems with Local Task Service
              roxy1987

              Thanks for your reply Maciej. I see the next task now. But completing all the task doesnt update the process instance details. Process instance stays in progress. This is when I restart the server.

              I even tried loading the same session but it didnt help. Need your help pls. Thanks.

              • 4. Re: Problems with Local Task Service
                calca

                Where are you checking if the process instance has finished? Can you share your process definition?

                 

                Thanks

                 

                Demian

                • 5. Re: Problems with Local Task Service
                  roxy1987

                  I am checking the status in the database. I cant share the proc def right now but wll do that 1st thing in the morning.

                  I was absolutely fine with jbpm5 when i used it with Servlets and JSPs etc. Now that I moved to EJBs, I have started facing issues.

                  I am a little confused with the way we are supposed to use KnowledgeSessions and KnowledgeBases. I use the same knowledge base and create a new session whenever I need it. This worked pretty well with servlets and since creating a KnowledgeSession is not a heavy job, as per the User Guide, I dont mind having many sessions. But with EJBs, things seem a lot different. May be coz of the fact that my technology stack is EJB and Websphere, and the transaction is supposed to be Container Managed.

                   

                  Confusion with session, kbases, whether or not to disconnect the task handlers, whether or not to disconnect the TaskClients, disposing the DBlogger.