use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class TemporalEvaluatorFactoryTest method testMetBy.
@Test
public void testMetBy() {
registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
EventFactHandle foo = new EventFactHandle(1, "foo", 1, 10, 8, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle bar = new EventFactHandle(2, "bar", 1, 2, 8, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle drool = new EventFactHandle(1, "drool", 1, 5, 3, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle mole = new EventFactHandle(1, "mole", 1, 4, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
final Object[][] data = { { foo, "metby", bar, Boolean.TRUE }, { foo, "metby", drool, Boolean.FALSE }, { foo, "metby", mole, Boolean.FALSE }, { foo, "not metby", bar, Boolean.FALSE }, { foo, "not metby", drool, Boolean.TRUE }, { foo, "not metby", mole, Boolean.TRUE }, { foo, "metby[1]", bar, Boolean.TRUE }, { foo, "metby[1]", drool, Boolean.FALSE }, { foo, "metby[1]", mole, Boolean.TRUE }, { foo, "metby[2]", drool, Boolean.TRUE }, { foo, "not metby[1]", bar, Boolean.FALSE }, { foo, "not metby[1]", drool, Boolean.TRUE }, { foo, "not metby[1]", mole, Boolean.FALSE }, { foo, "not metby[2]", drool, Boolean.FALSE } };
runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class TemporalEvaluatorFactoryTest method testMeets.
@Test
public void testMeets() {
registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 8, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle bar = new EventFactHandle(2, "bar", 1, 10, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle drool = new EventFactHandle(1, "drool", 1, 8, 5, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle mole = new EventFactHandle(1, "mole", 1, 11, 4, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
final Object[][] data = { { foo, "meets", bar, Boolean.TRUE }, { foo, "meets", drool, Boolean.FALSE }, { foo, "meets", mole, Boolean.FALSE }, { foo, "not meets", bar, Boolean.FALSE }, { foo, "not meets", drool, Boolean.TRUE }, { foo, "not meets", mole, Boolean.TRUE }, { foo, "meets[1]", bar, Boolean.TRUE }, { foo, "meets[1]", drool, Boolean.FALSE }, { foo, "meets[1]", mole, Boolean.TRUE }, { foo, "meets[2]", drool, Boolean.TRUE }, { foo, "not meets[1]", bar, Boolean.FALSE }, { foo, "not meets[1]", drool, Boolean.TRUE }, { foo, "not meets[1]", mole, Boolean.FALSE }, { foo, "not meets[2]", drool, Boolean.FALSE } };
runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class SlidingTimeWindow method expireFacts.
public void expireFacts(final Object context, final PropagationContext pctx, final InternalWorkingMemory workingMemory) {
TimerService clock = workingMemory.getTimerService();
long currentTime = clock.getCurrentTime();
SlidingTimeWindowContext queue = (SlidingTimeWindowContext) context;
EventFactHandle handle = queue.peek();
while (handle != null && isExpired(currentTime, handle)) {
queue.setExpiringHandle(handle);
queue.remove();
if (handle.isValid()) {
// if not expired yet, expire it
final PropagationContext expiresPctx = createPropagationContextForFact(workingMemory, handle, PropagationContext.Type.EXPIRATION);
ObjectTypeNode.doRetractObject(handle, expiresPctx, workingMemory);
}
queue.setExpiringHandle(null);
handle = queue.peek();
}
// update next expiration time
updateNextExpiration(handle, workingMemory, queue, nodeId);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class RuleExecutor method fireActivation.
public void fireActivation(InternalWorkingMemory wm, InternalAgenda agenda, Activation activation) throws ConsequenceException {
// We do this first as if a node modifies a fact that causes a recursion
// on an empty pattern
// we need to make sure it re-activates
wm.startOperation();
try {
wm.getAgendaEventSupport().fireBeforeActivationFired(activation, wm);
if (activation.getActivationGroupNode() != null) {
// We know that this rule will cancel all other activations in the group
// so lets remove the information now, before the consequence fires
final InternalActivationGroup activationGroup = activation.getActivationGroupNode().getActivationGroup();
activationGroup.removeActivation(activation);
agenda.clearAndCancelActivationGroup(activationGroup);
}
activation.setQueued(false);
try {
innerFireActivation(wm, agenda, activation, activation.getConsequence());
} finally {
// if the tuple contains expired events
for (Tuple tuple = activation.getTuple(); tuple != null; tuple = tuple.getParent()) {
if (tuple.getFactHandle() != null && tuple.getFactHandle().isEvent()) {
// can be null for eval, not and exists that have no right input
EventFactHandle handle = (EventFactHandle) tuple.getFactHandle();
// decrease the activation count for the event
handle.decreaseActivationsCount();
// handles "expire" only in stream mode.
if (handle.expirePartition() && handle.isExpired()) {
if (handle.getActivationsCount() <= 0) {
// and if no more activations, retract the handle
handle.getEntryPoint().delete(handle);
}
}
}
}
}
wm.getAgendaEventSupport().fireAfterActivationFired(activation, wm);
} finally {
wm.endOperation();
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class WindowNode method modifyRightTuple.
@Override
public void modifyRightTuple(RightTuple rightTuple, PropagationContext context, InternalWorkingMemory workingMemory) {
EventFactHandle originalFactHandle = (EventFactHandle) rightTuple.getFactHandle();
EventFactHandle cloneFactHandle = (EventFactHandle) rightTuple.getContextObject();
// make sure all fields are updated
originalFactHandle.quickCloneUpdate(cloneFactHandle);
// behavior modify
boolean isAllowed = true;
for (AlphaNodeFieldConstraint constraint : constraints) {
if (!constraint.isAllowed(cloneFactHandle, workingMemory)) {
isAllowed = false;
break;
}
}
if (isAllowed) {
ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples(cloneFactHandle.detachLinkedTuples());
this.sink.propagateModifyObject(cloneFactHandle, modifyPreviousTuples, context, workingMemory);
modifyPreviousTuples.retractTuples(context, workingMemory);
} else {
ObjectTypeNode.doRetractObject(cloneFactHandle, context, workingMemory);
}
}
Aggregations