Search in sources :

Example 36 with EventFactHandle

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

the class FactHandleMarshallingTest method createEventFactHandle.

private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
    // EntryPointNode
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = CoreComponentFactory.get().getNodeFactoryService();
    RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
    EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, rete, EntryPointId.DEFAULT);
    WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
    EventFactHandle factHandle = new EventFactHandle(1, new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
    return factHandle;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) RuleBasePartitionId(org.drools.core.common.RuleBasePartitionId) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) Person(org.drools.mvel.compiler.Person) Date(java.util.Date)

Example 37 with EventFactHandle

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

the class ExpireJobContextTimerInputMarshaller method deserialize.

@Override
public void deserialize(MarshallerReaderContext inCtx, ProtobufMessages.Timers.Timer timer) {
    ProtobufMessages.Timers.ExpireTimer expire = timer.getExpire();
    InternalFactHandle factHandle = inCtx.getHandles().get(expire.getHandleId());
    TimerService clock = inCtx.getWorkingMemory().getTimerService();
    JobContext jobctx = new ExpireJobContext(new WorkingMemoryReteExpireAction((EventFactHandle) factHandle), inCtx.getWorkingMemory());
    JobHandle jobHandle = clock.scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(expire.getNextFireTimestamp(), null));
    jobctx.setJobHandle(jobHandle);
    ((EventFactHandle) factHandle).addJob(jobHandle);
}
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)

Example 38 with EventFactHandle

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

the class BehaviorJobContextTimerOutputMarshaller method serialize.

@Override
public ProtobufMessages.Timers.Timer serialize(JobContext jobCtx, MarshallerWriteContext outputCtx) {
    // BehaviorJob, no state
    BehaviorJobContext bjobCtx = (BehaviorJobContext) jobCtx;
    // write out SlidingTimeWindowContext
    SlidingTimeWindowContext slCtx = (SlidingTimeWindowContext) bjobCtx.behaviorContext;
    EventFactHandle handle = slCtx.peek();
    return ProtobufMessages.Timers.Timer.newBuilder().setType(ProtobufMessages.Timers.TimerType.BEHAVIOR).setBehavior(ProtobufMessages.Timers.BehaviorTimer.newBuilder().setHandleId(handle.getId()).build()).build();
}
Also used : BehaviorJobContext(org.drools.core.rule.SlidingTimeWindow.BehaviorJobContext) EventFactHandle(org.drools.core.common.EventFactHandle) SlidingTimeWindowContext(org.drools.core.rule.SlidingTimeWindow.SlidingTimeWindowContext)

Example 39 with EventFactHandle

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

the class BehaviorJobContextTimerOutputMarshaller method write.

public void write(JobContext jobCtx, MarshallerWriteContext outputCtx) throws IOException {
    outputCtx.writeShort(PersisterEnums.BEHAVIOR_TIMER);
    // BehaviorJob, no state
    BehaviorJobContext bjobCtx = (BehaviorJobContext) jobCtx;
    // write out SlidingTimeWindowContext
    SlidingTimeWindowContext slCtx = (SlidingTimeWindowContext) bjobCtx.behaviorContext;
    EventFactHandle handle = slCtx.peek();
    outputCtx.writeLong(handle.getId());
}
Also used : BehaviorJobContext(org.drools.core.rule.SlidingTimeWindow.BehaviorJobContext) EventFactHandle(org.drools.core.common.EventFactHandle) SlidingTimeWindowContext(org.drools.core.rule.SlidingTimeWindow.SlidingTimeWindowContext)

Example 40 with EventFactHandle

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

the class NamedEntryPoint method update.

public InternalFactHandle update(InternalFactHandle handle, final Object object, final BitMask mask, final Class<?> modifiedClass, final Activation activation) {
    lock();
    try {
        this.reteEvaluator.startOperation();
        try {
            this.ruleBase.executeQueuedActions();
            // the handle might have been disconnected, so reconnect if it has
            if (handle.isDisconnected()) {
                handle = this.objectStore.reconnect(handle);
            }
            final Object originalObject = handle.getObject();
            final boolean changedObject = originalObject != object;
            if (!handle.getEntryPointId().equals(entryPoint)) {
                throw new IllegalArgumentException("Invalid Entry Point. You updated the FactHandle on entry point '" + handle.getEntryPointId() + "' instead of '" + getEntryPointId() + "'");
            }
            if (handle.isExpired()) {
                // let an expired event potentially (re)enters the objectStore, but make sure that it will be clear at the end of the inference cycle
                ((EventFactHandle) handle).setPendingRemoveFromStore(true);
            }
            final ObjectTypeConf typeConf = changedObject ? getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(this.entryPoint, object) : getObjectTypeConfigurationRegistry().getObjectTypeConf(object);
            if (changedObject || isEqualityBehaviour) {
                this.objectStore.updateHandle(handle, object);
            }
            this.handleFactory.increaseFactHandleRecency(handle);
            final PropagationContext propagationContext = pctxFactory.createPropagationContext(this.reteEvaluator.getNextPropagationIdCounter(), PropagationContext.Type.MODIFICATION, activation == null ? null : activation.getRule(), activation == null ? null : activation.getTuple().getTupleSink(), handle, entryPoint, mask, modifiedClass, null);
            if (typeConf.isTMSEnabled()) {
                TruthMaintenanceSystemFactory.get().getOrCreateTruthMaintenanceSystem(this).updateOnTms(handle, object, activation);
            }
            beforeUpdate(handle, object, activation, originalObject, propagationContext);
            update(handle, object, originalObject, typeConf, propagationContext);
        } finally {
            this.reteEvaluator.endOperation();
        }
    } finally {
        unlock();
    }
    return handle;
}
Also used : ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) PropagationContext(org.drools.core.spi.PropagationContext) 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