Search in sources :

Example 16 with EventFactHandle

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;
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) EventFactHandle(org.drools.core.common.EventFactHandle)

Example 17 with EventFactHandle

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;
}
Also used : EventFactHandle(org.drools.core.common.EventFactHandle)

Example 18 with EventFactHandle

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);
        }
    }
}
Also used : EventFactHandle(org.drools.core.common.EventFactHandle)

Example 19 with EventFactHandle

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());
    }
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Example 20 with EventFactHandle

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);
}
Also used : AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) WindowMemory(org.drools.core.reteoo.WindowNode.WindowMemory) EventFactHandle(org.drools.core.common.EventFactHandle) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Aggregations

EventFactHandle (org.drools.core.common.EventFactHandle)86 Test (org.junit.Test)51 KieSession (org.kie.api.runtime.KieSession)23 KieBase (org.kie.api.KieBase)18 InternalFactHandle (org.drools.core.common.InternalFactHandle)16 DisconnectedWorkingMemoryEntryPoint (org.drools.core.common.DisconnectedWorkingMemoryEntryPoint)13 DisconnectedWorkingMemoryEntryPoint (org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint)13 FactHandle (org.kie.api.runtime.rule.FactHandle)11 DuringEvaluatorDefinition (org.drools.core.base.evaluators.DuringEvaluatorDefinition)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)10 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)6 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)5 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)5 PropagationContext (org.drools.core.spi.PropagationContext)5 StockTick (org.drools.testcoverage.common.model.StockTick)5 EntryPointId (org.drools.core.rule.EntryPointId)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4