use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class PhreakQueryNode method doLeftUpdates.
public void doLeftUpdates(QueryElementNode queryNode, QueryElementNodeMemory qmem, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
InternalFactHandle fh = (InternalFactHandle) leftTuple.getContextObject();
DroolsQuery dquery = (DroolsQuery) fh.getObject();
dquery.setParameters(queryNode.getActualArguments(leftTuple, wm));
SegmentMemory qsmem = qmem.getQuerySegmentMemory();
LeftInputAdapterNode lian = (LeftInputAdapterNode) qsmem.getRootNode();
LiaNodeMemory lmem = (LiaNodeMemory) qsmem.getNodeMemories().getFirst();
if (dquery.isOpen()) {
// there is only one, all other LTs are peers
LeftTuple childLeftTuple = fh.getFirstLeftTuple();
LeftInputAdapterNode.doUpdateObject(childLeftTuple, childLeftTuple.getPropagationContext(), wm, lian, false, lmem, qmem.getQuerySegmentMemory());
} else {
if (fh.getFirstLeftTuple() != null) {
// @TODO remove later (mdp)
throw new RuntimeException("defensive programming while testing");
}
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(fh, leftTuple.getPropagationContext(), lian, wm, lm, false, dquery.isOpen());
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class PhreakQueryNode method doLeftInserts.
public void doLeftInserts(QueryElementNode queryNode, QueryElementNodeMemory qmem, StackEntry stackEntry, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = leftTuple.getPropagationContext();
InternalFactHandle handle = queryNode.createFactHandle(pCtx, wm, leftTuple);
DroolsQuery dquery = queryNode.createDroolsQuery(leftTuple, handle, stackEntry, qmem.getSegmentMemory().getPathMemories(), qmem, stackEntry.getSink(), wm);
LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(handle, pCtx, lian, wm, lm, false, dquery.isOpen());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class AccumulateNode method createResultFactHandle.
public InternalFactHandle createResultFactHandle(final PropagationContext context, final InternalWorkingMemory workingMemory, final LeftTuple leftTuple, final Object result) {
InternalFactHandle handle;
ProtobufMessages.FactHandle _handle = null;
if (context.getReaderContext() != null) {
Map<TupleKey, FactHandle> map = (Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle>) context.getReaderContext().nodeMemories.get(getId());
if (map != null) {
_handle = map.get(PersisterHelper.createTupleKey(leftTuple));
}
}
if (_handle != null) {
// create a handle with the given id
handle = workingMemory.getFactHandleFactory().newFactHandle(_handle.getId(), result, _handle.getRecency(), workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(context.getEntryPoint(), result), workingMemory, // so far, result is not an event
null);
} else {
handle = workingMemory.getFactHandleFactory().newFactHandle(result, workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(context.getEntryPoint(), result), workingMemory, // so far, result is not an event
null);
}
return handle;
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class FromNode method createFactHandle.
public InternalFactHandle createFactHandle(Tuple leftTuple, PropagationContext context, InternalWorkingMemory workingMemory, Object object) {
FactHandle _handle = null;
if (objectTypeConf == null) {
// use default entry point and object class. Notice that at this point object is assignable to resultClass
objectTypeConf = new ClassObjectTypeConf(workingMemory.getEntryPoint(), resultClass, workingMemory.getKnowledgeBase());
}
if (context.getReaderContext() != null) {
Map<TupleKey, List<FactHandle>> map = (Map<TupleKey, List<FactHandle>>) context.getReaderContext().nodeMemories.get(getId());
if (map != null) {
TupleKey key = PersisterHelper.createTupleKey(leftTuple);
List<FactHandle> list = map.get(key);
if (list != null && !list.isEmpty()) {
// it is a linked list, so the operation is fairly efficient
_handle = ((java.util.LinkedList<FactHandle>) list).removeFirst();
if (list.isEmpty()) {
map.remove(key);
}
}
}
}
InternalFactHandle handle;
if (_handle != null) {
// create a handle with the given id
handle = workingMemory.getFactHandleFactory().newFactHandle(_handle.getId(), object, _handle.getRecency(), objectTypeConf, workingMemory, null);
} else {
handle = workingMemory.getFactHandleFactory().newFactHandle(object, objectTypeConf, workingMemory, null);
}
return handle;
}
use of org.drools.core.common.InternalFactHandle 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.strategyContext.get(strategy), context, object)));
}
return _handle.build();
}
Aggregations