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, ReteEvaluator reteEvaluator) {
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, reteEvaluator)) {
isAllowed = false;
break;
}
}
if (isAllowed) {
ModifyPreviousTuples modifyPreviousTuples = new ModifyPreviousTuples(cloneFactHandle.detachLinkedTuples());
this.sink.propagateModifyObject(cloneFactHandle, modifyPreviousTuples, context, reteEvaluator);
modifyPreviousTuples.retractTuples(context, reteEvaluator);
} else {
ObjectTypeNode.doRetractObject(cloneFactHandle, context, reteEvaluator);
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class SlidingLengthWindow method assertFact.
/**
* @inheritDoc
*/
public boolean assertFact(final Object context, final InternalFactHandle handle, final PropagationContext pctx, final ReteEvaluator reteEvaluator) {
SlidingLengthWindowContext window = (SlidingLengthWindowContext) context;
window.pos = (window.pos + 1) % window.handles.length;
if (window.handles[window.pos] != null) {
final EventFactHandle previous = window.handles[window.pos];
// retract previous
final PropagationContext expiresPctx = createPropagationContextForFact(reteEvaluator, previous, PropagationContext.Type.EXPIRATION);
ObjectTypeNode.doRetractObject(previous, expiresPctx, reteEvaluator);
}
window.handles[window.pos] = (EventFactHandle) handle;
return true;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class SlidingTimeWindow method retractFact.
@Override
public void retractFact(final Object context, final InternalFactHandle fact, final PropagationContext pctx, final ReteEvaluator reteEvaluator) {
final SlidingTimeWindowContext queue = (SlidingTimeWindowContext) context;
final EventFactHandle handle = (EventFactHandle) fact;
// it may be a call back to expire the tuple that is already being expired
if (!handle.equals(queue.getExpiringHandle())) {
if (handle.equals(queue.peek())) {
// it was the head of the queue
queue.poll();
// update next expiration time
updateNextExpiration(queue.peek(), reteEvaluator, queue, nodeId);
} else {
queue.remove(handle);
}
if (queue.isEmpty() && queue.getJobHandle() != null) {
reteEvaluator.getTimerService().removeJob(queue.getJobHandle());
}
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class EvaluatorWrapper method loadHandles.
public void loadHandles(InternalFactHandle[] handles, InternalFactHandle rightHandle) {
InternalFactHandle localLeftHandle = null;
InternalFactHandle localRightHandle = null;
if (!selfLeft && handles != null) {
localLeftHandle = getFactHandle(leftBinding, handles);
}
if (selfRight) {
localRightHandle = rightHandle;
} else if (handles != null) {
localRightHandle = getFactHandle(rightBinding, handles);
}
// @FIXME else? what happens now (mdp) ? Maybe this can never happen?
this.rightLiteral = localRightHandle == null;
if (isTemporal()) {
if (localLeftHandle == null) {
localLeftHandle = rightHandle;
}
leftTimestamp = localLeftHandle instanceof EventFactHandle ? ((EventFactHandle) localLeftHandle).getStartTimestamp() : null;
rightTimestamp = localRightHandle instanceof EventFactHandle ? ((EventFactHandle) localRightHandle).getStartTimestamp() : null;
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class RuleExecutor method fireActivation.
public void fireActivation(ReteEvaluator reteEvaluator, ActivationsManager activationsManager, 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
reteEvaluator.startOperation();
try {
BeforeMatchFiredEvent beforeMatchFiredEvent = activationsManager.getAgendaEventSupport().fireBeforeActivationFired(activation, reteEvaluator);
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);
activationsManager.clearAndCancelActivationGroup(activationGroup);
}
activation.setQueued(false);
try {
innerFireActivation(reteEvaluator, activationsManager, activation, activation.getConsequence());
} finally {
// if the tuple contains expired events
for (Tuple tuple = activation.getTuple().skipEmptyHandles(); tuple != null; tuple = tuple.getParent()) {
if (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() && handle.getFirstRightTuple() == null && handle.getActivationsCount() <= 0) {
// and if no more activations, retract the handle
handle.getEntryPoint(reteEvaluator).delete(handle);
}
}
}
}
activationsManager.getAgendaEventSupport().fireAfterActivationFired(activation, reteEvaluator, beforeMatchFiredEvent);
} finally {
reteEvaluator.endOperation();
}
}
Aggregations