Search in sources :

Example 61 with EventFactHandle

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);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.core.common.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) DuringEvaluatorDefinition(org.drools.core.base.evaluators.DuringEvaluatorDefinition) Test(org.junit.Test)

Example 62 with EventFactHandle

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);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.core.common.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) DuringEvaluatorDefinition(org.drools.core.base.evaluators.DuringEvaluatorDefinition) Test(org.junit.Test)

Example 63 with EventFactHandle

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

Example 64 with EventFactHandle

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

Example 65 with EventFactHandle

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

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