4 Replies Latest reply on Feb 26, 2014 3:28 PM by Timothy Hahn

    Diagram not updated (using async. work item)

    Livia Hauser Newbie

      Hi All,

       

      last weekend I played arround with drools (5.3.0.CR1) and  jbpm (5.1.1.Final) on jboss 5.1.

      I have a simple bpmn:

      [1]start -> [2] timer ->[3]script -> [4]AsyncHandler -> [5]timer -> [6]script -> [7]end

       

      After my AsyncHandler calls completeWorkItem task [5] and [6] will executed. But if I take a look at the diagram task [4] is still highlighted.

       

      How I can make shure a user will see right/updated diagram?

       

      My WorkHandler to test a asynch behavior:

       

      public class AsyncWorkItemHandler implements WorkItemHandler {

       

           StatefulKnowledgeSession ksession;

       

       

          public AsyncWorkItemHandler(ProcessContext kcontext){

              super();

              this.ksession = (StatefulKnowledgeSession)kcontext.getKnowledgeRuntime();

          }

       

          public AsyncWorkItemHandler(StatefulKnowledgeSession ksession) {

              super();

              this.ksession = ksession;

       

         @Override

         public void executeWorkItem(WorkItem workItem, WorkItemManager manager){

       

              class WThread extends Thread{

       

                  int sessionId;

                  long itemId;

                  KnowledgeBase kbase;

                  Environment env;

       

                  public WThread(int sessionId,  long itemId,

                          KnowledgeBase kbase, Environment env) {

                      super();

                      this.sessionId = sessionId;;

                      this.itemId = itemId;

                      this.kbase = kbase;

                      this.env = env;

                  }

       

                  @Override

                  public void run(){

                      int seconds = 30;

                      System.out.println("thread for session " + this.sessionId + " (workitem "+ this.itemId +"), sleep " + seconds + "s");

                      try {

                          Thread.currentThread().sleep(seconds * 1000);

                      } catch (InterruptedException e) {

                          e.printStackTrace();

                      }

       

                      StatefulKnowledgeSession ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(this.sessionId, kbase, null, env);

                      ksession.getWorkItemManager().registerWorkItemHandler("AsyncTask", new AsyncWorkItemHandler(ksession));

                      ksession.getWorkItemManager().completeWorkItem(this.itemId, null);

                      System.out.println("thread for session " + this.sessionId + " (workitem "+ this.itemId +") end");

       

                      this.clean();

       

                  }

       

                     protected void clean(){

                         this.kbase = null;

                         this.env = null;

                  }

              }

       

              KnowledgeBase kbase = ksession.getKnowledgeBase();

              Environment env = ksession.getEnvironment();

              int sessionId = ksession.getId();

              long itemId = workItem.getId();

              WThread t = new WThread(sessionId, /*processId,*/ itemId, kbase, env);

              t.start();

            }

       

          }

       

      }

       

       

      Any hints?

       

      Many thx + greetings,

      Livia