3 Replies Latest reply on Aug 1, 2006 7:55 PM by brado

    Creating a timer doesn't save to the database

    brado

      Hello,

      I am trying to create a timer in a business process, and save it to the scheduler. I get no errors when creating or saving the timer. However, it does not appear that anything is getting saved to the database. The JBPM_TIMER table is empty. Here is the code I am executing inside of my business process ActionHandler's execute method:

      public void execute(ExecutionContext executionContext) throws Exception {
      log.debug("[execute]: Enter.");

      try {
      log.debug("[execute]: Getting context variables.");
      String transactionId = (String) executionContext
      .getVariable(NetworkNode.PVAR_transactionId);

      log.debug("[execute]: Creating solicit timer: "
      + executionContext.getTaskInstance());
      Timer timer = new Timer(executionContext.getToken());
      timer.setName("Solicit: " + transactionId);
      BusinessCalendar businessCalendar = new BusinessCalendar();
      Date dueDate = businessCalendar.findStartOfNextDay(new Date());
      timer.setDueDate(dueDate);
      timer.setTransitionName("solicitQuery");
      timer.setGraphElement(executionContext.getEventSource());
      timer.setTaskInstance(executionContext.getTaskInstance());
      SchedulerService schedulerService = (SchedulerService) Services
      .getCurrentService(Services.SERVICENAME_SCHEDULER);
      schedulerService.createTimer(timer);
      log.info("[execute]: Solicit timer created: " + timer);
      } catch (Exception ex) {
      if (ex instanceof NodeException) {
      throw ex;
      }
      log.error("[execute]: Error creating solicit timer: " + ex.getMessage());
      throw new NodeException("Error creating solicit timer: " + ex.getMessage(),
      ex, IErrorCode.Code.E_UNKNOWN_ERROR);
      } finally {
      executionContext.leaveNode();
      log.debug("[execute]: Exit.");
      }
      }

        • 1. Re: Creating a timer doesn't save to the database
          brado

          Ugh...laptop gone wild. Sorry about the ugly post above. Accidental hit of the return key before I formatted the code. Anyway, here it is in readable form:

          public void execute(ExecutionContext executionContext) throws Exception {
           log.debug("[execute]: Enter.");
          
           try {
           log.debug("[execute]: Getting context variables.");
           String transactionId = (String) executionContext.getVariable(NetworkNode.PVAR_transactionId);
          
           log.debug("[execute]: Creating solicit timer: " + executionContext.getTaskInstance());
           Timer timer = new Timer(executionContext.getToken());
           timer.setName("Solicit: " + transactionId);
           BusinessCalendar businessCalendar = new BusinessCalendar();
           Date dueDate = businessCalendar.findStartOfNextDay(new Date());
           timer.setDueDate(dueDate);
           timer.setTransitionName("solicitQuery");
           timer.setGraphElement(executionContext.getEventSource());
           timer.setTaskInstance(executionContext.getTaskInstance());
           SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
           schedulerService.createTimer(timer);
           log.info("[execute]: Solicit timer created: " + timer);
           } catch (Exception ex) {
           if (ex instanceof NodeException) {
           throw ex;
           }
           log.error("[execute]: Error creating solicit timer: " + ex.getMessage());
           throw new NodeException("Error creating solicit timer: " + ex.getMessage(),
           ex, IErrorCode.Code.E_UNKNOWN_ERROR);
           } finally {
           executionContext.leaveNode();
           log.debug("[execute]: Exit.");
           }
          }
          


          • 2. Re: Creating a timer doesn't save to the database
            kukeltje

            uhhmmmmm could it be that nothing is saved because nothing is saved. I mean, use the appropriate mechanisms e.g. the save(taskinstance) method on a jbpmContext

            • 3. Re: Creating a timer doesn't save to the database
              brado

              The code which wraps the execution of this business process saves the process instance both before the business process is executed and after. Here is the code:

              JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
              try {
               log.debug("[solicit]: Getting graph session.");
               GraphSession graphSession = jbpmContext.getGraphSession();
               log.debug("[solicit]: Finding process definition: Solicit");
               ProcessDefinition processDefinition = graphSession.findLatestProcessDefinition("Solicit");
               log.debug("[solicit]: Creating new process instance:Solicit");
               ProcessInstance processInstance = new ProcessInstance(processDefinition);
               // set variables
               log.debug("[solicit]: Creating new context instance.");
               ContextInstance ci = processInstance.getContextInstance();
               log.debug("[solicit]: Setting context instance variables.");
               ci.setVariable(PVAR_authenticationToken, securityToken);
               ci.setVariable(PVAR_request, request);
               ci.setVariable(PVAR_returnURL, returnURL);
               ci.setVariable(PVAR_bpparameters, parameters);
               log.debug("[solicit]: Saving process instance: Solicit");
               jbpmContext.save(processInstance);
               log.debug("[solicit]: Executing business process: Solicit");
               processInstance.signal();
               log.debug("[solicit]: Saving process instance: Solicit");
               jbpmContext.save(processInstance);
               String transactionId = (String) processInstance.getContextInstance().getVariable(PVAR_queryResult);
               log.info("[solicit]: Returning transactionId=" + transactionId);
               return transactionId;
              } catch (Exception ex) {
               Throwable cause = ex.getCause();
               if (cause != null && cause instanceof NodeException) {
               throw (NodeException) cause;
               }
               log.error("[solicit]: Unknown error occurred while trying to execute business process: Solicit", ex);
               throw new NodeException("Unknown error occurred while trying to execute business process: Solicit", ex, ErrorCode.Code.E_UNKNOWN_ERROR);
              } finally {
               jbpmContext.close();
               log.debug("[solicit]: Exit.");
              }
              


              So I save the process instance prior, the business process which creates the timer and saves it to the scheduler is invoked, and the business process completes, and the process instance is saved again. Shouldn't this save the timer to the database?

              Thanks,

              Brad