use of org.drools.core.marshalling.impl.ProtobufMessages.FactHandle in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeRIANodeMemory.
private static ProtobufMessages.NodeMemory writeRIANodeMemory(final int nodeId, final BaseNode node, final NodeMemories memories) {
RightInputAdapterNode riaNode = (RightInputAdapterNode) node;
ObjectSink[] sinks = riaNode.getObjectSinkPropagator().getSinks();
BetaNode betaNode = (BetaNode) sinks[0];
Memory betaMemory = memories.peekNodeMemory(betaNode);
if (betaMemory == null) {
return null;
}
BetaMemory bm;
if (betaNode.getType() == NodeTypeEnums.AccumulateNode) {
bm = ((AccumulateMemory) betaMemory).getBetaMemory();
} else {
bm = (BetaMemory) betaMemory;
}
// for RIA nodes, we need to store the ID of the created handles
bm.getRightTupleMemory().iterator();
if (bm.getRightTupleMemory().size() > 0) {
ProtobufMessages.NodeMemory.RIANodeMemory.Builder _ria = ProtobufMessages.NodeMemory.RIANodeMemory.newBuilder();
final org.drools.core.util.Iterator it = bm.getRightTupleMemory().iterator();
// iterates over all propagated handles and assert them to the new sink
for (RightTuple entry = (RightTuple) it.next(); entry != null; entry = (RightTuple) it.next()) {
LeftTuple leftTuple = entry instanceof LeftTuple ? // with phreak the entry is always both a right and a left tuple
(LeftTuple) entry : // this is necessary only for reteoo
(LeftTuple) entry.getFactHandle().getObject();
InternalFactHandle handle = (InternalFactHandle) leftTuple.getFactHandle();
if (handle == null) {
continue;
}
FactHandle _handle = ProtobufMessages.FactHandle.newBuilder().setId(handle.getId()).setRecency(handle.getRecency()).build();
_ria.addContext(ProtobufMessages.NodeMemory.RIANodeMemory.RIAContext.newBuilder().setTuple(PersisterHelper.createTuple(leftTuple)).setResultHandle(_handle).build());
}
return ProtobufMessages.NodeMemory.newBuilder().setNodeId(nodeId).setNodeType(ProtobufMessages.NodeMemory.NodeType.RIA).setRia(_ria.build()).build();
}
return null;
}
Aggregations