1 Reply Latest reply on Apr 9, 2009 4:27 AM by Joram Barrez

    Ensure consistency of logging

    Thomas Kriechbaum Newbie

      How can I ensure, that the logging service is notified consistently?

      jBPM notifies the Logging Service at the context's auto save phase, that means that I have to register the appropriate process instance for auto save in advance.

      JbpmContext context = ...;
      ProcessInstance pi = ...;
      context.addAutoSaveProcessInstance(pi);
      ...
      // auto save is performed and logging service gets invoked
      context.close();
      

      In the following sample the logging service is not invoked, because the task instance is loaded and ended within a separate context without registering the appropriate process instance.

      JbpmContext context = ...;
      TaskInstance task = context.getTaskInstance(id);
      task.end();
      context.close();


      Do I really have to register all affected process instances to get logging done right? How can this work with complex process definitions (e.g. process definition with several subprocesses)?

        • 1. Re: Ensure consistency of logging
          Joram Barrez Master

          Simply call the jBPMContext.save(processInstance) operation before the close() method is invoked.

          The logging for the process instance, including the subprocesses, will be stored in the log table.

          For a task, you should do

          JbpmContext context = ...;
          TaskInstance task = context.getTaskInstance(id);
          task.end();
          context.save(task.getProcessInstance);
          context.close();
          


          Or, better, use the jBPM command service. The commands automatically save the process instance (and closes the context):

          TaskEndCommand command = new TaskEndCommand(taskId);
          commandService.execute(command);