Esempio n. 1
0
  @Override
  public Object execute(Context context) {
    KieSession kieSession = ((KnowledgeCommandContext) context).getKieSession();
    TimerManager tm = getTimerManager(kieSession);

    RuleFlowProcessInstance wfp =
        (RuleFlowProcessInstance) kieSession.getProcessInstance(processInstanceId);

    for (NodeInstance nodeInstance : wfp.getNodeInstances()) {
      if (nodeInstance instanceof TimerNodeInstance) {
        TimerNodeInstance tni = (TimerNodeInstance) nodeInstance;
        if (tni.getNodeName().equals(timerName)) {
          TimerInstance timer = tm.getTimerMap().get(tni.getTimerId());

          tm.cancelTimer(timer.getTimerId());
          TimerInstance newTimer = new TimerInstance();

          if (delay != 0) {
            long diff = System.currentTimeMillis() - timer.getActivated().getTime();
            newTimer.setDelay(delay * 1000 - diff);
          }
          newTimer.setPeriod(period);
          newTimer.setRepeatLimit(repeatLimit);
          newTimer.setTimerId(timer.getTimerId());
          tm.registerTimer(newTimer, wfp);

          tni.internalSetTimerId(newTimer.getId());

          break;
        }
      }
    }
    return null;
  }
Esempio n. 2
0
 private void triggerTimer(TimerInstance timerInstance) {
   for (Map.Entry<Timer, DroolsAction> entry : getEventBasedNode().getTimers().entrySet()) {
     if (entry.getKey().getId() == timerInstance.getTimerId()) {
       executeAction((Action) entry.getValue().getMetaData("Action"));
       return;
     }
   }
 }