Package org.jbpm.process.instance.timer

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


      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


  public ProcessRuntimeImpl(InternalKnowledgeRuntime kruntime) {
    this.kruntime = kruntime;
    ((CompositeClassLoader) getRootClassLoader()).addClassLoader( getClass().getClassLoader() );
    initProcessInstanceManager();
    initSignalManager();
    timerManager = new TimerManager(kruntime, kruntime.getTimerService());
        processEventSupport = new ProcessEventSupport();
        initProcessEventListeners();
        initProcessActivationListener();
  }
View Full Code Here

    this.workingMemory = workingMemory;
    this.kruntime = (InternalKnowledgeRuntime) workingMemory.getKnowledgeRuntime();
    ((CompositeClassLoader) getRootClassLoader()).addClassLoader( getClass().getClassLoader() );
    initProcessInstanceManager();
    initSignalManager();
    timerManager = new TimerManager(kruntime, kruntime.getTimerService());
        processEventSupport = new ProcessEventSupport();
        initProcessEventListeners();
        initProcessActivationListener();
  }
View Full Code Here

    }

    public void writeProcessTimers(MarshallerWriteContext context) throws IOException {
        ObjectOutputStream stream = context.stream;

        TimerManager timerManager = ((InternalProcessRuntime) ((InternalWorkingMemory) context.wm).getProcessRuntime()).getTimerManager();
        long timerId = timerManager.internalGetTimerId();
        stream.writeLong( timerId );
       
        // need to think on how to fix this
        // stream.writeObject( timerManager.getTimerService() );
       
        List<TimerInstance> timers = new ArrayList<TimerInstance>( timerManager.getTimers() );
        Collections.sort( timers,
                          new Comparator<TimerInstance>() {
                              public int compare(TimerInstance o1,
                                                 TimerInstance o2) {
                                  return (int) (o2.getId() - o1.getId());
View Full Code Here

    }

    public void readProcessTimers(MarshallerReaderContext context) throws IOException {
        ObjectInputStream stream = context.stream;

        TimerManager timerManager = ((InternalProcessRuntime) ((InternalWorkingMemory) context.wm).getProcessRuntime()).getTimerManager();
        timerManager.internalSetTimerId( stream.readLong() );
       
        // 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

    // activate timers
    Map<Timer, DroolsAction> timers = getEventBasedNode().getTimers();
    if (timers != null) {
      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

    }
   
  private void cancelTimers() {
    // deactivate still active timers
    if (timerInstances != null) {
      TimerManager timerManager = ((InternalProcessRuntime)
        getProcessInstance().getKnowledgeRuntime().getProcessRuntime()).getTimerManager();
      for (Long id: timerInstances) {
        timerManager.cancelTimer(id);
      }
    }
  }
View Full Code Here

    }

    public void clearProcessInstancesState() {
        try {
            // at this point only timers are considered as state that needs to be cleared
            TimerManager timerManager = ((InternalProcessRuntime)kruntime.getProcessRuntime()).getTimerManager();
           
            for (ProcessInstance processInstance: new ArrayList<ProcessInstance>(getProcessInstances())) {
                WorkflowProcessInstance pi = ((WorkflowProcessInstance) processInstance);
               
                for (org.kie.api.runtime.process.NodeInstance nodeInstance : pi.getNodeInstances()) {
                    if (nodeInstance instanceof TimerNodeInstance){
                        if (((TimerNodeInstance)nodeInstance).getTimerInstance() != null) {
                            timerManager.cancelTimer(((TimerNodeInstance)nodeInstance).getTimerInstance().getId());
                        }
                    } else if (nodeInstance instanceof StateBasedNodeInstance) {
                        List<Long> timerIds = ((StateBasedNodeInstance) nodeInstance).getTimerInstances();
                        if (timerIds != null) {
                            for (Long id: timerIds) {
                                timerManager.cancelTimer(id);
                            }
                        }
                    }
                }
               
View Full Code Here

TOP

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

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.