Package org.jbpm.process.instance.timer

Examples of org.jbpm.process.instance.timer.TimerInstance


        RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance() {
      private static final long serialVersionUID = 510l;
      public void signalEvent(String type, Object event) {
            if ("timerTriggered".equals(type)) {
              TimerInstance timer = (TimerInstance) event;
                System.out.println("Timer " + timer.getId() + " triggered");
                counter++;
            }
          }
        };
        processInstance.setKnowledgeRuntime(((InternalWorkingMemory) workingMemory).getKnowledgeRuntime());
        processInstance.setId(1234);
        ((InternalProcessRuntime) ((InternalWorkingMemory) workingMemory).getProcessRuntime()).getProcessInstanceManager()
          .internalAddProcessInstance(processInstance);

        new Thread(new Runnable() {
      public void run() {
            workingMemory.fireUntilHalt();        
      }
        }).start();

        TimerManager timerManager = ((InternalProcessRuntime) ((InternalWorkingMemory) workingMemory).getProcessRuntime()).getTimerManager();
        TimerInstance timer = new TimerInstance();
        timerManager.registerTimer(timer, processInstance);
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          // do nothing
        }
        assertEquals(1, counter);
       
        counter = 0;
        timer = new TimerInstance();
        timer.setDelay(500);
        timerManager.registerTimer(timer, processInstance);
        assertEquals(0, counter);
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          // do nothing
        }
        assertEquals(1, counter);
       
        counter = 0;
        timer = new TimerInstance();
        timer.setDelay(500);
        timer.setPeriod(300);
        timerManager.registerTimer(timer, processInstance);
        assertEquals(0, counter);
        try {
          Thread.sleep(700);
        } catch (InterruptedException e) {
          // do nothing
        }
        assertEquals(1, counter);
       
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // do nothing
        }
        // we can't know exactly how many times this will fire as timers are not precise, but should be atleast 4
        assertTrue( counter >= 4 );
       
        timerManager.cancelTimer(timer.getId());
        int lastCount = counter;
        try {           
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          // do nothing
View Full Code Here


        // still need to think on how to fix this.
//        TimerService service = (TimerService) stream.readObject();
//        timerManager.setTimerService( service );

        while ( stream.readShort() == PersisterEnums.TIMER ) {
            TimerInstance timer = readTimer( context );
            timerManager.internalAddTimer( timer );
        }
    }
View Full Code Here

    }

    public TimerInstance readTimer(MarshallerReaderContext context) throws IOException {
        ObjectInputStream stream = context.stream;

        TimerInstance timer = new TimerInstance();
        timer.setId( stream.readLong() );
        timer.setTimerId( stream.readLong() );
        timer.setDelay( stream.readLong() );
        timer.setPeriod( stream.readLong() );
        timer.setProcessInstanceId( stream.readLong() );
        timer.setActivated( new Date( stream.readLong() ) );
        if ( stream.readBoolean() ) {
            timer.setLastTriggered( new Date( stream.readLong() ) );
        }
        return timer;
    }
View Full Code Here

      addTimerListener();
      timerInstances = new ArrayList<Long>(timers.size());
      TimerManager timerManager = ((InternalProcessRuntime)
        getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager();
      for (Timer timer: timers.keySet()) {
        TimerInstance timerInstance = createTimerInstance(timer);
        timerManager.registerTimer(timerInstance, (ProcessInstance) getProcessInstance());
        timerInstances.add(timerInstance.getId());
      }
    }
  }
View Full Code Here

      }
    }
  }
 
    protected TimerInstance createTimerInstance(Timer timer) {
      TimerInstance timerInstance = new TimerInstance();
      timerInstance.setDelay(resolveValue(timer.getDelay()));
      if (timer.getPeriod() == null) {
        timerInstance.setPeriod(0);
      } else {
        timerInstance.setPeriod(resolveValue(timer.getPeriod()));
      }
      timerInstance.setTimerId(timer.getId());
      return timerInstance;
    }
View Full Code Here

      }
    }

    public void signalEvent(String type, Object event) {
      if ("timerTriggered".equals(type)) {
        TimerInstance timerInstance = (TimerInstance) event;
            if (timerInstances.contains(timerInstance.getId())) {
                triggerTimer(timerInstance);
            }
      }
    }
View Full Code Here

    public void internalTrigger(NodeInstance from, String type) {
        if (!org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
            throw new IllegalArgumentException(
                "A TimerNode only accepts default incoming connections!");
        }
        TimerInstance timer = createTimerInstance();
        if (getTimerInstances() == null) {
          addTimerListener();
        }
        ((InternalProcessRuntime) getProcessInstance().getKnowledgeRuntime().getProcessRuntime())
          .getTimerManager().registerTimer(timer, (ProcessInstance) getProcessInstance());
        timerId = timer.getId();
    }
View Full Code Here

        timerId = timer.getId();
    }
   
    protected TimerInstance createTimerInstance() {
      Timer timer = getTimerNode().getTimer();
      TimerInstance timerInstance = new TimerInstance();
      timerInstance.setDelay(resolveValue(timer.getDelay()));
      if (timer.getPeriod() == null) {
        timerInstance.setPeriod(0);
      } else {
        timerInstance.setPeriod(resolveValue(timer.getPeriod()));
      }
      timerInstance.setTimerId(timer.getId());
      return timerInstance;
    }
View Full Code Here

      }
    }

    public void signalEvent(String type, Object event) {
      if ("timerTriggered".equals(type)) {
        TimerInstance timer = (TimerInstance) event;
            if (timer.getId() == timerId) {
                triggerCompleted(timer.getPeriod() == 0);
            }
      }
    }
View Full Code Here

TOP

Related Classes of org.jbpm.process.instance.timer.TimerInstance

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.