Package org.drools.process.instance.timer

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


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


      return timerInstance;
    }

    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

        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.setWorkingMemory((InternalWorkingMemory) workingMemory);
        processInstance.setId(1234);
        ((InternalWorkingMemory) workingMemory).getProcessInstanceManager()
          .internalAddProcessInstance(processInstance);

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

        TimerManager timerManager = workingMemory.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 static 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

TOP

Related Classes of org.drools.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.