Search in sources :

Example 6 with FactHandle

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;
}
Also used : BetaNode(org.drools.core.reteoo.BetaNode) InternalFactHandle(org.drools.core.common.InternalFactHandle) FactHandle(org.drools.core.marshalling.impl.ProtobufMessages.FactHandle) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) Memory(org.drools.core.common.Memory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ObjectTypeNodeMemory(org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) FromMemory(org.drools.core.reteoo.FromNode.FromMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) ObjectSink(org.drools.core.reteoo.ObjectSink) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode)

Aggregations

InternalFactHandle (org.drools.core.common.InternalFactHandle)6 FactHandle (org.drools.core.marshalling.impl.ProtobufMessages.FactHandle)6 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 EventFactHandle (org.drools.core.common.EventFactHandle)4 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)4 LeftTuple (org.drools.core.reteoo.LeftTuple)4 Map (java.util.Map)3 ObjectTypeNodeMemory (org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory)3 QueryElementNodeMemory (org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory)3 RightTuple (org.drools.core.reteoo.RightTuple)3 TupleKey (org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey)2 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)2 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)2 List (java.util.List)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1 Memory (org.drools.core.common.Memory)1 ProtobufInputMarshaller (org.drools.core.marshalling.impl.ProtobufInputMarshaller)1 ProtobufMessages (org.drools.core.marshalling.impl.ProtobufMessages)1 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1