Class FlowControlledStream<IN,​OUT>

  • Type Parameters:
    IN - the type of entries returned by this stream
    OUT - the type of message used for flow control in this stream
    All Implemented Interfaces:
    io.grpc.stub.ClientResponseObserver<OUT,​IN>, io.grpc.stub.StreamObserver<IN>
    Direct Known Subclasses:
    AbstractIncomingInstructionStream, FlowControlledBuffer, SubscriptionQueryStream

    public abstract class FlowControlledStream<IN,​OUT>
    extends Object
    implements io.grpc.stub.ClientResponseObserver<OUT,​IN>
    Abstract implementation of a ClientResponseObserver providing flow control.
    • Constructor Detail

      • FlowControlledStream

        protected FlowControlledStream​(String clientId,
                                       int permits,
                                       int refillBatch)
        Constructs a FlowControlledStream.
        Parameters:
        clientId - the client identifier which initiated this stream
        permits - the number of permits this stream should receive
        refillBatch - the number of permits to be consumed prior to requesting new permits
    • Method Detail

      • enableFlowControl

        public void enableFlowControl()
        Enables flow control for this stream. Will only set up flow control if the permits batch size is larger than 0.
      • buildFlowControlMessage

        protected abstract OUT buildFlowControlMessage​(FlowControl flowControl)
        Build a flow control message of type OUT based on the given flowControl.
        Parameters:
        flowControl - the FlowControl message used to base this implementation's flow control message on
        Returns:
        the message used by this implementation to request new entries of type IN
      • buildInitialFlowControlMessage

        protected OUT buildInitialFlowControlMessage​(FlowControl flowControl)
        Builds the initial flow control message of type OUT based on the given flowControl.
        Parameters:
        flowControl - the FlowControl message used to base this implementation's flow control message on
        Returns:
        the initial message used by this implementation to request new entries of type IN
      • markConsumed

        protected void markConsumed()
        Notifier when an entry has been consumed from this stream. Keeps track of the number of permits which has been consumed and will automatically ask for new permits if the permitsBatch size has been reached.
      • beforeStart

        public void beforeStart​(io.grpc.stub.ClientCallStreamObserver<OUT> requestStream)
        Specified by:
        beforeStart in interface io.grpc.stub.ClientResponseObserver<IN,​OUT>
      • outboundStream

        protected io.grpc.stub.ClientCallStreamObserver<OUT> outboundStream()
        Return the ClientCallStreamObserver serving as the outbound stream. Can be used to send additional messages required to tap into the flow control of this stream, or the complete the stream altogether.
        Returns:
        the ClientCallStreamObserver serving as the outbound stream