Search in sources :

Example 76 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testFinishedBy.

@Test
public void testFinishedBy() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 5, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 7, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { foo, "finishedby", bar, Boolean.TRUE }, { foo, "finishedby", drool, Boolean.FALSE }, { foo, "finishedby", mole, Boolean.FALSE }, { bar, "finishedby", foo, Boolean.FALSE }, { foo, "not finishedby", bar, Boolean.FALSE }, { foo, "not finishedby", drool, Boolean.TRUE }, { foo, "not finishedby", mole, Boolean.TRUE }, { bar, "not finishedby", foo, Boolean.TRUE }, { foo, "finishedby[1]", bar, Boolean.TRUE }, { foo, "finishedby[1]", drool, Boolean.FALSE }, { foo, "finishedby[1]", mole, Boolean.TRUE }, { bar, "finishedby[1]", foo, Boolean.FALSE }, { foo, "not finishedby[1]", bar, Boolean.FALSE }, { foo, "not finishedby[1]", drool, Boolean.TRUE }, { foo, "not finishedby[1]", mole, Boolean.FALSE }, { bar, "not finishedby[1]", foo, Boolean.TRUE }, { foo, "finishedby[3]", mole, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 77 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.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) Test(org.junit.Test)

Example 78 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeFactHandle.

private static ProtobufMessages.FactHandle writeFactHandle(MarshallerWriteContext context, ObjectMarshallingStrategyStore objectMarshallingStrategyStore, InternalFactHandle handle) throws IOException {
    ProtobufMessages.FactHandle.Builder _handle = ProtobufMessages.FactHandle.newBuilder();
    _handle.setType(getHandleType(handle));
    _handle.setId(handle.getId());
    _handle.setRecency(handle.getRecency());
    if (_handle.getType() == ProtobufMessages.FactHandle.HandleType.EVENT) {
        // is event
        EventFactHandle efh = (EventFactHandle) handle;
        _handle.setTimestamp(efh.getStartTimestamp());
        _handle.setDuration(efh.getDuration());
        _handle.setIsExpired(efh.isExpired());
        _handle.setActivationsCount(efh.getActivationsCount());
        _handle.setOtnCount(efh.getOtnCount());
    }
    if (handle.getEqualityKey() != null && handle.getEqualityKey().getStatus() == EqualityKey.JUSTIFIED) {
        _handle.setIsJustified(true);
    } else {
        _handle.setIsJustified(false);
    }
    Object object = handle.getObject();
    if (object != null) {
        ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(object);
        Integer index = context.getStrategyIndex(strategy);
        _handle.setStrategyIndex(index);
        _handle.setObject(ByteString.copyFrom(strategy.marshal(context.getStrategyContext().get(strategy), (ObjectOutputStream) context, object)));
    }
    return _handle.build();
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.drools.serialization.protobuf.ProtobufMessages.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) EventFactHandle(org.drools.core.common.EventFactHandle)

Example 79 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class InputMarshaller method readFactHandle.

public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
    int type = context.readInt();
    long id = context.readLong();
    long recency = context.readLong();
    long startTimeStamp = 0;
    long duration = 0;
    boolean expired = false;
    long activationsCount = 0;
    if (type == 2) {
        startTimeStamp = context.readLong();
        duration = context.readLong();
        expired = context.readBoolean();
        activationsCount = context.readLong();
    }
    int strategyIndex = context.readInt();
    ObjectMarshallingStrategy strategy = null;
    // This is the old way of de/serializing strategy objects
    if (strategyIndex >= 0) {
        strategy = context.getResolverStrategyFactory().getStrategy(strategyIndex);
    } else // This is the new way
    if (strategyIndex == -2) {
        String strategyClassName = context.readUTF();
        if (!StringUtils.isEmpty(strategyClassName)) {
            strategy = context.getResolverStrategyFactory().getStrategyObject(strategyClassName);
            if (strategy == null) {
                throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
            }
        }
    }
    // If either way retrieves a strategy, use it
    Object object = null;
    if (strategy != null) {
        object = strategy.read((ObjectInputStream) context);
    }
    EntryPoint entryPoint = null;
    if (context.readBoolean()) {
        String entryPointId = context.readUTF();
        if (entryPointId != null && !entryPointId.equals("")) {
            entryPoint = ((RuleRuntime) context.getWorkingMemory()).getEntryPoint(entryPointId);
        }
    }
    EntryPointId confEP;
    if (entryPoint != null) {
        confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
    } else {
        confEP = context.getWorkingMemory().getEntryPoint();
    }
    ObjectTypeConf typeConf = context.getWorkingMemory().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(confEP, object);
    InternalFactHandle handle = null;
    switch(type) {
        case 0:
            {
                handle = new DefaultFactHandle(id, object, recency, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                break;
            }
        case 1:
            {
                handle = new QueryElementFactHandle(object, id, recency);
                break;
            }
        case 2:
            {
                handle = new EventFactHandle(id, object, recency, startTimeStamp, duration, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                ((EventFactHandle) handle).setExpired(expired);
                ((EventFactHandle) handle).setActivationsCount(activationsCount);
                break;
            }
        default:
            {
                throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + type);
            }
    }
    return handle;
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) EntryPointId(org.drools.core.rule.EntryPointId) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) InternalFactHandle(org.drools.core.common.InternalFactHandle) ObjectInputStream(java.io.ObjectInputStream)

Example 80 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class ExpireJobContextTimerInputMarshaller method read.

public void read(ProtobufMarshallerReaderContext inCtx) throws IOException, ClassNotFoundException {
    InternalFactHandle factHandle = inCtx.getHandles().get(inCtx.readLong());
    long nextTimeStamp = inCtx.readLong();
    TimerService clock = inCtx.getWorkingMemory().getTimerService();
    JobContext jobctx = new ExpireJobContext(new WorkingMemoryReteExpireAction((EventFactHandle) factHandle), inCtx.getWorkingMemory());
    JobHandle handle = clock.scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(nextTimeStamp, null));
    jobctx.setJobHandle(handle);
}
Also used : ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) JobHandle(org.drools.core.time.JobHandle) EventFactHandle(org.drools.core.common.EventFactHandle) JobContext(org.drools.core.time.JobContext) ExpireJobContext(org.drools.core.reteoo.ObjectTypeNode.ExpireJobContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryReteExpireAction(org.drools.core.impl.WorkingMemoryReteExpireAction) TimerService(org.drools.core.time.TimerService)

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