3 Replies Latest reply on Mar 27, 2006 7:15 AM by Romin Irani

    Tracing the Process Instance

    Romin Irani Newbie

      Is any API available to get a trace of the entire Process Instance that has ended or running.

      So, for e.g. consider the following process definition (Pls ignore the exact syntax) :

      1) START
      2) NODE-A
      2) NODE-B
      4) FORK --> NODE-C
      --> NODE-D
      5) JOIN
      6) NODE-E
      7) END

      I create a process instance and run through it i.e. the process instance ends. For the instance, I can get hold of different things like:
      1) Any tasks
      2) Variables and their values
      3) Current Node -- where it is

      But how do I get an entire trace i.e. it went through the above steps ? The variables at end step, etc.

      Thanks
      Romin.

        • 1. Re: Tracing the Process Instance
          Alexey Kakunin Newbie

          Yes, of cource - it is LogInstances

          Here is simples way to get all tracing information for the root token of the process instance:

          LoggingSession logSession = JbpmContext.getCurrentContext().getLoggingSession();
          
          Map logMap = logSession.findLogsByProcessInstance(m_process.getId());
          
          List resultLogs = new ArrayList();
          
          Collection logs = (Collection)logMap.get(processInstance.getRootToken());
          


          • 2. Re: Tracing the Process Instance
            Ronald van Kuijk Master

            but there might be more than a root token. You should check for child tokens as well.

            • 3. Re: Tracing the Process Instance
              Romin Irani Newbie

              Thanks for the replies. This has helped me going -- but I still have lots of questions:

              1) I had overlooked the documentation and I was not calling a ctx.save(ProcessInstance). As a result of this, the JBPM_LOG table was empty. I added the ctx.save(...) call and now the table is getting populated.

              However, I need to confirm / clarify / ask the following:
              1) I am starting my Processes by using the following code:


               JbpmConfiguration jbpmConfig = JbpmConfiguration.getInstance();
               JbpmContext ctx = jbpmConfig.createJbpmContext();
               try {
               //Create Instance
               ProcessInstance PI = ctx.getGraphSession().findLatestProcessDefinition("some-process-def").createProcessInstance();
              
               //Initialize Process Context Variables
               Map ProcessMap = new HashMap();
               ProcessMap.put("...",...);
               PI.getContextInstance().addVariables(ProcessMap);
              
               //Start the Process
               PI.getRootToken().signal();
               ctx.save(PI);
              
               System.out.println(PI.hasEnded());
               }
               catch (Exception e) {
               System.out.println(e.toString());
               }
               finally {
               ctx.close();
               }


              Is the above piece of code good enough? Am I still missing something?

              2) My process definitions typically consist of Automatic Nodes -- where I have either a beanshell script doing something or an ActionHandler implementation. How can make sure that everything that happens in each of these nodes gets logged into the JBPM_LOG table. Is the above code good enough.

              3) If my server is halted while executing some workflow instances, then I have written code that will load all running Process instances on startup and signal them to continue execution. Should I load all these Instances with a loadProcessInstanceforUpdate and then signal() -- so that everything is logged?

              4) If I am handling a Task Node, should I load the task with LoadTaskInstanceforUpdate() and then do a TaskInstance.end() -- so that everything is logged?

              I would like to be pointed out to some sample code (if possible ) in the test package so that I can view how the complete logs can be retrieved from the Database.

              Could someone explain the logic behind retrieving the logs as pointed out by the posts below. I used the
              :
              
              LoggingSession logSession = JbpmContext.getCurrentContext().getLoggingSession();
              
              Map logMap = logSession.findLogsByProcessInstance(m_process.getId()


              Isnt this sufficient ? Do we have some utility method somewhere that simply prints like a toString() of the whole Log for the instance. That would more than meet the requirements from the purpose of debugging by reading this log quickly.