Search in sources :

Example 11 with Trigger

use of org.drools.core.time.Trigger in project drools by kiegroup.

the class JDKTimerServiceTest method testSingleExecutionJob.

@Test
public void testSingleExecutionJob() throws Exception {
    SessionConfiguration config = SessionConfiguration.newInstance();
    config.setClockType(ClockType.REALTIME_CLOCK);
    TimerService timeService = TimerServiceFactory.getTimerService(config);
    Trigger trigger = new DelayedTrigger(100);
    HelloWorldJobContext ctx = new HelloWorldJobContext("hello world", timeService);
    timeService.scheduleJob(new HelloWorldJob(), ctx, trigger);
    Thread.sleep(500);
    timeService.shutdown();
    assertEquals(1, ctx.getList().size());
}
Also used : Trigger(org.drools.core.time.Trigger) SessionConfiguration(org.drools.core.SessionConfiguration) TimerService(org.drools.core.time.TimerService) Test(org.junit.Test)

Example 12 with Trigger

use of org.drools.core.time.Trigger in project drools by kiegroup.

the class CompositeMaxDurationTimerTest method testMixedDurationAndTimer.

@Test
public void testMixedDurationAndTimer() {
    CompositeMaxDurationTimer timer = new CompositeMaxDurationTimer();
    timer.addDurationTimer(new DurationTimer(25));
    timer.addDurationTimer(new DurationTimer(50));
    timer.addDurationTimer(new DurationTimer(70));
    timer.setTimer(new IntervalTimer(null, null, 6, 40, 25));
    Date timestamp = new Date();
    Trigger trigger = timer.createTrigger(timestamp.getTime(), null, null, null, null, null, null);
    // ignores the first interval timer at 65
    assertEquals(new Date(timestamp.getTime() + 70), trigger.hasNextFireTime());
    assertEquals(new Date(timestamp.getTime() + 90), trigger.nextFireTime());
    assertEquals(new Date(timestamp.getTime() + 115), trigger.nextFireTime());
    assertEquals(new Date(timestamp.getTime() + 140), trigger.nextFireTime());
    assertNull(trigger.nextFireTime());
    assertNull(trigger.hasNextFireTime());
}
Also used : Trigger(org.drools.core.time.Trigger) Date(java.util.Date) Test(org.junit.Test)

Example 13 with Trigger

use of org.drools.core.time.Trigger in project drools by kiegroup.

the class CompositeMaxDurationTimerTest method testJustMaxDuration.

@Test
public void testJustMaxDuration() {
    CompositeMaxDurationTimer timer = new CompositeMaxDurationTimer();
    timer.addDurationTimer(new DurationTimer(25));
    timer.addDurationTimer(new DurationTimer(50));
    timer.addDurationTimer(new DurationTimer(70));
    Date timestamp = new Date();
    Trigger trigger = timer.createTrigger(timestamp.getTime(), null, null, null, null, null, null);
    assertEquals(new Date(timestamp.getTime() + 70), trigger.hasNextFireTime());
    assertNull(trigger.nextFireTime());
    assertNull(trigger.hasNextFireTime());
}
Also used : Trigger(org.drools.core.time.Trigger) Date(java.util.Date) Test(org.junit.Test)

Example 14 with Trigger

use of org.drools.core.time.Trigger in project drools by kiegroup.

the class TimerNodeTimerInputMarshaller method deserialize.

@Override
public void deserialize(MarshallerReaderContext inCtx, ProtobufMessages.Timers.Timer _timer) {
    ProtobufMessages.Timers.TimerNodeTimer _tn = _timer.getTimerNode();
    int timerNodeId = _tn.getNodeId();
    TupleKey tuple = PersisterHelper.createTupleKey(_tn.getTuple());
    Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, _tn.getTrigger());
    PhreakTimerNode.Scheduler scheduler = inCtx.removeTimerNodeScheduler(timerNodeId, tuple);
    if (scheduler != null) {
        scheduler.schedule(trigger);
    }
}
Also used : PhreakTimerNode(org.drools.core.phreak.PhreakTimerNode) Trigger(org.drools.core.time.Trigger) TupleKey(org.drools.core.marshalling.TupleKey)

Aggregations

Trigger (org.drools.core.time.Trigger)14 Date (java.util.Date)6 IntervalTrigger (org.drools.core.time.impl.IntervalTrigger)6 CronTrigger (org.drools.core.time.impl.CronTrigger)5 Test (org.junit.Test)5 JobHandle (org.drools.core.time.JobHandle)4 TimerService (org.drools.core.time.TimerService)4 SessionConfiguration (org.drools.core.SessionConfiguration)3 ByteString (com.google.protobuf.ByteString)2 TupleKey (org.drools.core.marshalling.TupleKey)2 CompositeMaxDurationTrigger (org.drools.core.time.impl.CompositeMaxDurationTrigger)2 PointInTimeTrigger (org.drools.core.time.impl.PointInTimeTrigger)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 ReteEvaluator (org.drools.core.common.ReteEvaluator)1 TupleKey (org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey)1 Builder (org.drools.core.marshalling.impl.ProtobufMessages.ProcessData.Builder)1 PhreakTimerNode (org.drools.core.phreak.PhreakTimerNode)1 Builder (org.drools.serialization.protobuf.ProtobufMessages.ProcessData.Builder)1 GlobalTimerService (org.jbpm.process.core.timer.impl.GlobalTimerService)1