Class MergeCursorContinuation<B extends Message.Builder,​C extends RecordCursorContinuation>

  • Type Parameters:
    B - the builder for message type of the continuation proto message
    C - type of the continuation
    All Implemented Interfaces:
    RecordCursorContinuation

    @API(INTERNAL)
    public abstract class MergeCursorContinuation<B extends Message.Builder,​C extends RecordCursorContinuation>
    extends Object
    implements RecordCursorContinuation
    Common code for handling the continuations of MergeCursors. The continuations for these cursors are constructed from a Protobuf message containing information on the state of each child cursor. This class handles caching that Protobuf message and its byte representation so that subsequent calls to get the continuation are fast. It also abstracts away some of the logic for converting a list of continuations into a single Protobuf message, but this is still somewhat clunky because Protobuf does not support Message inheritance (which limits the opportunity for polymorphism).
    • Method Detail

      • setFirstChild

        protected abstract void setFirstChild​(@Nonnull
                                              B builder,
                                              @Nonnull
                                              C continuation)
        Fill in the Protobuf builder with the information from the first child. For backwards-compatibility reasons, cursors may handle this differently than the other children. This method will be called before setSecondChild(B, C) and all calls to addOtherChild(B, C).
        Parameters:
        builder - a builder for the Protobuf continuation
        continuation - the first child's continuation
      • setSecondChild

        protected abstract void setSecondChild​(@Nonnull
                                               B builder,
                                               @Nonnull
                                               C continuation)
        Fill in the Protobuf builder with the information from the second child. For backwards-compatibility reasons, cursors may handle this differently than the other children. This method will be called after setFirstChild(B, C) and before all calls to addOtherChild(B, C).
        Parameters:
        builder - a builder for the Protobuf continuation
        continuation - the second child's continuation
      • addOtherChild

        protected abstract void addOtherChild​(@Nonnull
                                              B builder,
                                              @Nonnull
                                              C continuation)
        Fill in the Protobuf builder with the information for a child other than the first or second child. For backwards-compatibility reasons, cursors may handle those two children differently than the other children. This method will be called in the same order as the continuations in getContinuations().
        Parameters:
        builder - a builder for the Protobuf continuation
        continuation - a child other than the first or second child
      • newProtoBuilder

        @Nonnull
        protected abstract B newProtoBuilder()
        Get a new builder instance for the Protobuf message associated with this continuation. This should typically be implemented by calling the newBuilder() method on the appropriate message type.
        Returns:
        a new builder for the underlying Protobuf message type
      • toBytes

        @Nullable
        public byte[] toBytes()
        Description copied from interface: RecordCursorContinuation
        Serialize this continuation to a byte array. This method must always return the same array contents (but not necessarily the same array). If RecordCursorContinuation.isEnd() returns true, then toBytes() must return null.
        Specified by:
        toBytes in interface RecordCursorContinuation
        Returns:
        a (possibly null) byte array containing a binary serialization of this continuation
      • getContinuations

        @Nonnull
        protected List<C> getContinuations()