Search in sources :

Example 1 with FactHandle

use of org.drools.serialization.protobuf.ProtobufMessages.FactHandle in project drools by kiegroup.

the class ProtobufOutputMarshaller method writeQueryElementNodeMemory.

private static ProtobufMessages.NodeMemory writeQueryElementNodeMemory(final int nodeId, final Memory memory, final InternalWorkingMemory wm) {
    org.drools.core.util.Iterator<LeftTuple> it = LeftTupleIterator.iterator(wm, ((QueryElementNodeMemory) memory).getNode());
    ProtobufMessages.NodeMemory.QueryElementNodeMemory.Builder _query = ProtobufMessages.NodeMemory.QueryElementNodeMemory.newBuilder();
    for (LeftTuple leftTuple = it.next(); leftTuple != null; leftTuple = it.next()) {
        InternalFactHandle handle = (InternalFactHandle) leftTuple.getContextObject();
        FactHandle _handle = ProtobufMessages.FactHandle.newBuilder().setId(handle.getId()).setRecency(handle.getRecency()).build();
        ProtobufMessages.NodeMemory.QueryElementNodeMemory.QueryContext.Builder _context = ProtobufMessages.NodeMemory.QueryElementNodeMemory.QueryContext.newBuilder().setTuple(PersisterHelper.createTuple(leftTuple)).setHandle(_handle);
        LeftTuple childLeftTuple = leftTuple.getFirstChild();
        while (childLeftTuple != null) {
            RightTuple rightParent = childLeftTuple.getRightParent();
            _context.addResult(ProtobufMessages.FactHandle.newBuilder().setId(rightParent.getFactHandle().getId()).setRecency(rightParent.getFactHandle().getRecency()).build());
            while (childLeftTuple != null && childLeftTuple.getRightParent() == rightParent) {
                // skip to the next child that has a different right parent
                childLeftTuple = childLeftTuple.getHandleNext();
            }
        }
        _query.addContext(_context.build());
    }
    return _query.getContextCount() > 0 ? ProtobufMessages.NodeMemory.newBuilder().setNodeId(nodeId).setNodeType(ProtobufMessages.NodeMemory.NodeType.QUERY_ELEMENT).setQueryElement(_query.build()).build() : null;
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) FactHandle(org.drools.serialization.protobuf.ProtobufMessages.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) InternalFactHandle(org.drools.core.common.InternalFactHandle) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) ObjectTypeNodeMemory(org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory)

Aggregations

DefaultFactHandle (org.drools.core.common.DefaultFactHandle)1 EventFactHandle (org.drools.core.common.EventFactHandle)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)1 LeftTuple (org.drools.core.reteoo.LeftTuple)1 ObjectTypeNodeMemory (org.drools.core.reteoo.ObjectTypeNode.ObjectTypeNodeMemory)1 QueryElementNodeMemory (org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory)1 RightTuple (org.drools.core.reteoo.RightTuple)1 FactHandle (org.drools.serialization.protobuf.ProtobufMessages.FactHandle)1