Package org.jbpm.job

Examples of org.jbpm.job.Timer


        } else {
          throw new ClassCastException("timer info ("+info.getClass().getName()+") is not of the expected class "+TimerInfo.class.getName());
        }
      }
      TimerInfo timerInfo = (TimerInfo) info;
      Timer timer = (Timer) localCommandService.execute(new ExecuteTimerCommand(timerInfo.getTimerId()));
      // if the timer has repeat
      if ( (timer!=null)
           && (timer.getRepeat()!=null)
         ) {
        // create a new timer
        log.debug("scheduling timer for repeat at "+timer.getDueDate());
        createTimer(timer);
      }
    } catch (Exception e) {
      JbpmException jbpmException = new JbpmException("couldn't execute timer", e);
      log.error(jbpmException);
View Full Code Here


  public ExecuteTimerCommand(long timerId) {
    this.timerId = timerId;
  }

  public Object execute(JbpmContext jbpmContext) throws Exception {
    Timer timer = (Timer) jbpmContext.getJobSession().getJob(timerId);
    if (timer!=null) {
      log.debug("executing timer "+timerId);
      timer.execute(jbpmContext);
    } else {
      log.info("execution of timer "+timerId+" was skipped cause the timer was deleted from the database");
    }
    return timer;
  }
View Full Code Here

    for (Job job : jobs)
    {
      if (job instanceof Timer)
      {
        // check all timers if connected to a GraphElement
        Timer timer = (Timer)job;
        if (timer.getGraphElement()!=null) {
         
          // and change the reference (take name mappings into account!)
          if (timer.getGraphElement() instanceof Task) {
            // change to new task definition
            Task oldTask = (Task)timer.getGraphElement();
            TaskNode oldNode =  oldTask.getTaskNode();
            timer.setGraphElement(
                findReplacementTask(newDef, oldNode, oldTask));
          }
          else {
            // change to new node
            GraphElement oldNode = timer.getGraphElement();
            // TODO: What with other GraphElements?
            timer.setGraphElement(
                findReplacementNode(newDef, oldNode));
          }         
        }
      }
    }
View Full Code Here

      jpdlReader.addProblem(new Problem(Problem.LEVEL_WARNING, "ignoring repeat on timer with transition "+actionElement.asXML()));
    }
  }

  public void execute(ExecutionContext executionContext) throws Exception {
    Timer timer = createTimer(executionContext);
    SchedulerService schedulerService = (SchedulerService) Services.getCurrentService(Services.SERVICENAME_SCHEDULER);
    schedulerService.createTimer(timer);
  }
View Full Code Here

    Date baseDate = null;
    Date dueDateDate = null;
    Duration duration;
    String durationString = null;
    String durationSeparator = null;
    Timer timer = new Timer(executionContext.getToken());
    timer.setName(timerName);
    timer.setRepeat(repeat);
    if (dueDate!=null) {
      if (dueDate.startsWith("#")) {
        String baseDateEL = dueDate.substring(0,dueDate.indexOf("}")+1);
        Object o = JbpmExpressionEvaluator.evaluate(baseDateEL, executionContext);
        if (o instanceof Date) {
          baseDate = (Date) o;         
        } else {
          if (o instanceof Calendar) {
            baseDate = ((Calendar) o).getTime();
          } else {
            throw new JbpmException("Invalid basedate type: " + baseDateEL + " is of type " + o.getClass().getName() +". Only Date and Calendar are supported");
          }
        }
        int endOfELIndex = dueDate.indexOf("}");
        if (endOfELIndex < (dueDate.length() -1) ) {
          durationSeparator = dueDate.substring(endOfELIndex+1).trim().substring(0,1);
          if ( !(durationSeparator.equals("+") || durationSeparator.equals("-") ) ){
            throw new JbpmException("Invalid duedate, + or - missing after EL");
          }
          durationString = dueDate.substring(endOfELIndex+1).trim();
        }
      } else {
        durationString = dueDate;
      }
      if (baseDate != null && (durationString == null || durationString.length() == 0)) {
        dueDateDate = baseDate;
      } else {
        duration = new Duration(durationString);
        dueDateDate = businessCalendar.add( (baseDate != null) ? baseDate : Clock.getCurrentTime(), duration );
      }
      timer.setDueDate(dueDateDate);
    }
    timer.setAction(timerAction);
    timer.setTransitionName(transitionName);
    timer.setGraphElement(executionContext.getEventSource());
    timer.setTaskInstance(executionContext.getTaskInstance());
   
    // if this action was executed for a graph element
    if ( (getEvent()!=null)
         && (getEvent().getGraphElement()!=null)
       ) {
View Full Code Here

        {
            for(Job job: jobs)
            {
                if (job instanceof Timer)
                {
                    final Timer timer = (Timer)job ;
                    if (timerName.equals(timer.getName()))
                    {
                        deleteJob(timer) ;
                    }
                }
            }
View Full Code Here

                {
                    for(Job job: jobs)
                    {
                        if (job instanceof Timer)
                        {
                            final Timer timer = (Timer)job ;
                            deleteJob(timer) ;
                        }
                    }
                }
            }
View Full Code Here

     * Execute the command.
     * @param jbpmContext The jBPM context associated with the execution.
     * @throws Exception for errors during execution.
     */
    public Object execute(JbpmContext jbpmContext) throws Exception {
      Timer timer = jbpmContext.getJobSession().loadTimer(timerId);
     
      // register process instance for automatic save
      // see https://jira.jboss.org/jira/browse/JBPM-1015
      ProcessInstance processInstance = timer.getProcessInstance();
      jbpmContext.addAutoSaveProcessInstance(processInstance);
     
      if (JobUtil.isDeleted(timer)) {
        if (log.isDebugEnabled()) {
          log.debug("timer " + timerId + " was deleted");
        }
        return null;
      }
      if (timer.isSuspended()) {
        if (log.isDebugEnabled()) {
          log.debug(timer + " is suspended");
        }
        RetryExecutor.handleSuspendedTimer(timer) ;
        return null ;
      }
      if (redelivered) {
          if (timer.getRetries() > 0) {
              timer.setRetries(timer.getRetries() - 1);
              if (log.isDebugEnabled()) {
                log.debug("Rescheduling timer " + timer.getId() + ", " + timer.getDueDate());
              }
              jbpmContext.getServices().getSchedulerService().createTimer(timer);
          } else {
              log.error("Timer retry count exceeded for timer " + timer.getId());
          }
          return null ;
      }
      timer.setLockOwner(getClass().getName()); // prevent others from removing timer
      log.debug("executing " + timer);
      try {
        if (timer.execute(jbpmContext)) {
          jbpmContext.getServices().getSchedulerService().deleteTimer(timer);
        } else if (timer.getRepeat() != null) {
            if (log.isDebugEnabled()) {
                log.debug("scheduling timer for repeat on " + timer.getDueDate());
            }
            jbpmContext.getServices().getSchedulerService().createTimer(timer);
        }
      }
      catch (Exception e) {
View Full Code Here

                        if (RETRY_EXECUTOR.equals(job.getLockOwner()))
                        {
                            job.setLockOwner(null) ;
                            if (job instanceof Timer)
                            {
                                final Timer timer = (Timer)job ;
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("Rescheduling timer " + timer.getId());
                                }
                                jbpmContext.getServices().getSchedulerService().createTimer(timer);
                            }
                            else
                            {
View Full Code Here

  }

  public void saveJob(Job job) {
    session.saveOrUpdate(job);
    if (job instanceof Timer) {
      Timer timer = (Timer) job;
      Action action = timer.getAction();
      if ( (action!=null)
           && (! session.contains(action))
         ) {
        log.debug("cascading timer save to timer action");
        session.save(action);
View Full Code Here

TOP

Related Classes of org.jbpm.job.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.