use of org.drools.core.rule.IntervalProviderConstraint in project drools by kiegroup.
the class BuildUtils method gatherTemporalRelationships.
private void gatherTemporalRelationships(List<?> constraints, Map<Declaration, Interval> temporal) {
for (Object obj : constraints) {
if (obj instanceof IntervalProviderConstraint) {
IntervalProviderConstraint constr = (IntervalProviderConstraint) obj;
if (constr.isTemporal()) {
// if a constraint already exists, calculate the intersection
Declaration[] decs = constr.getRequiredDeclarations();
// only calculate relationships to other event patterns
if (decs.length > 0 && decs[0].isPatternDeclaration() && decs[0].getPattern().getObjectType().isEvent()) {
Declaration target = decs[0];
Interval interval = temporal.get(target);
if (interval == null) {
interval = constr.getInterval();
temporal.put(target, interval);
} else {
interval.intersect(constr.getInterval());
}
}
}
} else if (obj instanceof AbstractCompositeConstraint) {
gatherTemporalRelationships(Arrays.asList(((AbstractCompositeConstraint) obj).getBetaConstraints()), temporal);
}
}
}
use of org.drools.core.rule.IntervalProviderConstraint 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);
}
}
}
}
}
Aggregations