Search in sources :

Example 1 with PointInTimeTrigger

use of org.drools.core.time.impl.PointInTimeTrigger in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeTrigger.

public static ProtobufMessages.Trigger writeTrigger(Trigger trigger, MarshallerWriteContext outCtx) {
    if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = (CronTrigger) trigger;
        ProtobufMessages.Trigger.CronTrigger.Builder _cron = ProtobufMessages.Trigger.CronTrigger.newBuilder().setStartTime(cronTrigger.getStartTime().getTime()).setRepeatLimit(cronTrigger.getRepeatLimit()).setRepeatCount(cronTrigger.getRepeatCount()).setCronExpression(cronTrigger.getCronEx().getCronExpression());
        if (cronTrigger.getEndTime() != null) {
            _cron.setEndTime(cronTrigger.getEndTime().getTime());
        }
        if (cronTrigger.getNextFireTime() != null) {
            _cron.setNextFireTime(cronTrigger.getNextFireTime().getTime());
        }
        if (cronTrigger.getCalendarNames() != null) {
            for (String calendarName : cronTrigger.getCalendarNames()) {
                _cron.addCalendarName(calendarName);
            }
        }
        return ProtobufMessages.Trigger.newBuilder().setType(ProtobufMessages.Trigger.TriggerType.CRON).setCron(_cron.build()).build();
    } else if (trigger instanceof IntervalTrigger) {
        IntervalTrigger intTrigger = (IntervalTrigger) trigger;
        ProtobufMessages.Trigger.IntervalTrigger.Builder _interval = ProtobufMessages.Trigger.IntervalTrigger.newBuilder().setStartTime(intTrigger.getStartTime().getTime()).setRepeatLimit(intTrigger.getRepeatLimit()).setRepeatCount(intTrigger.getRepeatCount()).setPeriod(intTrigger.getPeriod());
        if (intTrigger.getEndTime() != null) {
            _interval.setEndTime(intTrigger.getEndTime().getTime());
        }
        if (intTrigger.getNextFireTime() != null) {
            _interval.setNextFireTime(intTrigger.getNextFireTime().getTime());
        }
        if (intTrigger.getCalendarNames() != null) {
            for (String calendarName : intTrigger.getCalendarNames()) {
                _interval.addCalendarName(calendarName);
            }
        }
        return ProtobufMessages.Trigger.newBuilder().setType(ProtobufMessages.Trigger.TriggerType.INTERVAL).setInterval(_interval.build()).build();
    } else if (trigger instanceof PointInTimeTrigger) {
        PointInTimeTrigger pinTrigger = (PointInTimeTrigger) trigger;
        return ProtobufMessages.Trigger.newBuilder().setType(ProtobufMessages.Trigger.TriggerType.POINT_IN_TIME).setPit(ProtobufMessages.Trigger.PointInTimeTrigger.newBuilder().setNextFireTime(pinTrigger.hasNextFireTime().getTime()).build()).build();
    } else if (trigger instanceof CompositeMaxDurationTrigger) {
        CompositeMaxDurationTrigger cmdTrigger = (CompositeMaxDurationTrigger) trigger;
        ProtobufMessages.Trigger.CompositeMaxDurationTrigger.Builder _cmdt = ProtobufMessages.Trigger.CompositeMaxDurationTrigger.newBuilder();
        if (cmdTrigger.getMaxDurationTimestamp() != null) {
            _cmdt.setMaxDurationTimestamp(cmdTrigger.getMaxDurationTimestamp().getTime());
        }
        if (cmdTrigger.getTimerCurrentDate() != null) {
            _cmdt.setTimerCurrentDate(cmdTrigger.getTimerCurrentDate().getTime());
        }
        if (cmdTrigger.getTimerTrigger() != null) {
            _cmdt.setTimerTrigger(writeTrigger(cmdTrigger.getTimerTrigger(), outCtx));
        }
        return ProtobufMessages.Trigger.newBuilder().setType(ProtobufMessages.Trigger.TriggerType.COMPOSITE_MAX_DURATION).setCmdt(_cmdt.build()).build();
    }
    throw new RuntimeException("Unable to serialize Trigger for type: " + trigger.getClass());
}
Also used : CompositeMaxDurationTrigger(org.drools.core.time.impl.CompositeMaxDurationTrigger) CronTrigger(org.drools.core.time.impl.CronTrigger) IntervalTrigger(org.drools.core.time.impl.IntervalTrigger) Trigger(org.drools.core.time.Trigger) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) CompositeMaxDurationTrigger(org.drools.core.time.impl.CompositeMaxDurationTrigger) CronTrigger(org.drools.core.time.impl.CronTrigger) Builder(org.drools.core.marshalling.impl.ProtobufMessages.ProcessData.Builder) ByteString(com.google.protobuf.ByteString) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) IntervalTrigger(org.drools.core.time.impl.IntervalTrigger)

Example 2 with PointInTimeTrigger

use of org.drools.core.time.impl.PointInTimeTrigger in project drools by kiegroup.

the class SlidingTimeWindow method updateNextExpiration.

protected void updateNextExpiration(final InternalFactHandle fact, final InternalWorkingMemory workingMemory, final Behavior.Context context, final int nodeId) {
    TimerService clock = workingMemory.getTimerService();
    if (fact != null) {
        long nextTimestamp = ((EventFactHandle) fact).getStartTimestamp() + getSize();
        if (nextTimestamp < clock.getCurrentTime()) {
            // Past and out-of-order events should not be insert,
            // but the engine silently accepts them anyway, resulting in possibly undesirable behaviors
            workingMemory.queueWorkingMemoryAction(new BehaviorExpireWMAction(nodeId, this, context));
        } else {
            JobContext jobctx = new BehaviorJobContext(nodeId, workingMemory, this, context);
            JobHandle handle = clock.scheduleJob(job, jobctx, new PointInTimeTrigger(nextTimestamp, null, null));
            jobctx.setJobHandle(handle);
        }
    }
}
Also used : JobHandle(org.drools.core.time.JobHandle) JobContext(org.drools.core.time.JobContext) PointInTimeTrigger(org.drools.core.time.impl.PointInTimeTrigger) TimerService(org.drools.core.time.TimerService)

Aggregations

PointInTimeTrigger (org.drools.core.time.impl.PointInTimeTrigger)2 ByteString (com.google.protobuf.ByteString)1 Builder (org.drools.core.marshalling.impl.ProtobufMessages.ProcessData.Builder)1 JobContext (org.drools.core.time.JobContext)1 JobHandle (org.drools.core.time.JobHandle)1 TimerService (org.drools.core.time.TimerService)1 Trigger (org.drools.core.time.Trigger)1 CompositeMaxDurationTrigger (org.drools.core.time.impl.CompositeMaxDurationTrigger)1 CronTrigger (org.drools.core.time.impl.CronTrigger)1 IntervalTrigger (org.drools.core.time.impl.IntervalTrigger)1