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 InternalWorkingMemory workingMemory) {
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(workingMemory, previous, PropagationContext.Type.EXPIRATION);
ObjectTypeNode.doRetractObject(previous, expiresPctx, workingMemory);
}
window.handles[window.pos] = (EventFactHandle) handle;
return true;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class SlidingTimeWindow method assertFact.
public boolean assertFact(final Object context, final InternalFactHandle fact, final PropagationContext pctx, final InternalWorkingMemory workingMemory) {
final SlidingTimeWindowContext queue = (SlidingTimeWindowContext) context;
final EventFactHandle handle = (EventFactHandle) fact;
long currentTime = workingMemory.getTimerService().getCurrentTime();
if (isExpired(currentTime, handle)) {
return false;
}
queue.add(handle);
if (queue.peek() == handle) {
// update next expiration time
updateNextExpiration(handle, workingMemory, queue, nodeId);
}
return true;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class SlidingTimeWindow method retractFact.
public void retractFact(final Object context, final InternalFactHandle fact, final PropagationContext pctx, final InternalWorkingMemory workingMemory) {
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 (queue.getExpiringHandle() != handle) {
if (queue.peek() == handle) {
// it was the head of the queue
queue.poll();
// update next expiration time
updateNextExpiration(queue.peek(), workingMemory, queue, nodeId);
} else {
queue.remove(handle);
}
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class ReteooFactHandleFactory method newFactHandle.
/* (non-Javadoc)
* @see org.kie.reteoo.FactHandleFactory#newFactHandle(long)
*/
public InternalFactHandle newFactHandle(final int id, final Object object, final long recency, final ObjectTypeConf conf, final InternalWorkingMemory workingMemory, final WorkingMemoryEntryPoint wmEntryPoint) {
if (conf != null && conf.isEvent()) {
TypeDeclaration type = conf.getTypeDeclaration();
long timestamp;
if (type != null && type.getTimestampExtractor() != null) {
timestamp = type.getTimestampExtractor().getLongValue(workingMemory, object);
} else {
timestamp = workingMemory.getTimerService().getCurrentTime();
}
long duration = 0;
if (type != null && type.getDurationExtractor() != null) {
duration = type.getDurationExtractor().getLongValue(workingMemory, object);
}
return new EventFactHandle(id, object, recency, timestamp, duration, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
} else {
return new DefaultFactHandle(id, object, recency, wmEntryPoint != null ? wmEntryPoint : workingMemory, conf != null && conf.isTrait());
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class WindowNode method assertObject.
public void assertObject(final InternalFactHandle factHandle, final PropagationContext pctx, final InternalWorkingMemory workingMemory) {
EventFactHandle evFh = (EventFactHandle) factHandle;
for (AlphaNodeFieldConstraint constraint : constraints) {
if (!constraint.isAllowed(evFh, workingMemory)) {
return;
}
}
RightTuple rightTuple = new RightTupleImpl(evFh, this);
rightTuple.setPropagationContext(pctx);
// this is cloned, as we need to separate the child RightTuple references
InternalFactHandle clonedFh = evFh.cloneAndLink();
rightTuple.setContextObject(clonedFh);
// process the behavior
final WindowMemory memory = workingMemory.getNodeMemory(this);
if (!behavior.assertFact(memory.behaviorContext, clonedFh, pctx, workingMemory)) {
return;
}
this.sink.propagateAssertObject(clonedFh, pctx, workingMemory);
}
Aggregations