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;
}
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);
}
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();
}
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());
}
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;
}
Aggregations