Search in sources :

Example 6 with Timer

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

the class PatternBuilder method checkDelaying.

private void checkDelaying(final BuildContext context, final Constraint constraint) {
    if (constraint instanceof IntervalProviderConstraint) {
        // variable constraints always require a single declaration
        Declaration target = constraint.getRequiredDeclarations()[0];
        if (target.isPatternDeclaration() && target.getPattern().getObjectType().isEvent()) {
            long uplimit = ((IntervalProviderConstraint) constraint).getInterval().getUpperBound();
            // only makes sense to add the new timer if the uplimit is not infinity (Long.MAX_VALUE)
            if (uplimit >= 0 && uplimit < Long.MAX_VALUE) {
                Timer timer = context.getRule().getTimer();
                DurationTimer durationTimer = new DurationTimer(uplimit);
                durationTimer.setEventFactHandle(target);
                if (timer instanceof CompositeMaxDurationTimer) {
                    // already a composite so just add
                    ((CompositeMaxDurationTimer) timer).addDurationTimer(durationTimer);
                } else {
                    if (timer == null) {
                        // no timer exists, so ok on it's own
                        timer = durationTimer;
                    } else {
                        // timer exists so we need to make a composite
                        CompositeMaxDurationTimer temp = new CompositeMaxDurationTimer();
                        if (timer instanceof DurationTimer) {
                            // previous timer was a duration, so add another DurationTimer
                            temp.addDurationTimer((DurationTimer) timer);
                        } else {
                            // previous timer was not a duration, so set it as the delegate Timer.
                            temp.setTimer(context.getRule().getTimer());
                        }
                        // now add the new durationTimer
                        temp.addDurationTimer(durationTimer);
                        timer = temp;
                    }
                    // with the composite made, reset it on the Rule
                    context.getRule().setTimer(timer);
                }
            }
        }
    }
}
Also used : CompositeMaxDurationTimer(org.drools.core.time.impl.CompositeMaxDurationTimer) DurationTimer(org.drools.core.time.impl.DurationTimer) CompositeMaxDurationTimer(org.drools.core.time.impl.CompositeMaxDurationTimer) Timer(org.drools.core.time.impl.Timer) DurationTimer(org.drools.core.time.impl.DurationTimer) CompositeMaxDurationTimer(org.drools.core.time.impl.CompositeMaxDurationTimer) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Declaration(org.drools.core.rule.Declaration) IntervalProviderConstraint(org.drools.core.rule.IntervalProviderConstraint)

Aggregations

Timer (org.drools.core.time.impl.Timer)6 TimerNodeTimer (org.drools.core.marshalling.impl.ProtobufMessages.Timers.TimerNodeTimer)2 LeftTuple (org.drools.core.reteoo.LeftTuple)2 TimerService (org.drools.core.time.TimerService)2 Calendars (org.kie.api.runtime.Calendars)2 ParseException (java.text.ParseException)1 StringTokenizer (java.util.StringTokenizer)1 DroolsError (org.drools.compiler.compiler.DroolsError)1 RuleBuildError (org.drools.compiler.compiler.RuleBuildError)1 MVELObjectExpression (org.drools.core.base.mvel.MVELObjectExpression)1 UpdateContext (org.drools.core.common.UpdateContext)1 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)1 Declaration (org.drools.core.rule.Declaration)1 IntervalProviderConstraint (org.drools.core.rule.IntervalProviderConstraint)1 NamedConsequence (org.drools.core.rule.NamedConsequence)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 BaseTimer (org.drools.core.time.impl.BaseTimer)1 CompositeMaxDurationTimer (org.drools.core.time.impl.CompositeMaxDurationTimer)1 CronExpression (org.drools.core.time.impl.CronExpression)1 CronTimer (org.drools.core.time.impl.CronTimer)1