Class AbstractStream.TransportState

java.lang.Object
io.grpc.internal.AbstractStream.TransportState
All Implemented Interfaces:
ApplicationThreadDeframer.TransportExecutor, ApplicationThreadDeframerListener.TransportExecutor, MessageDeframer.Listener
Direct Known Subclasses:
AbstractClientStream.TransportState, AbstractServerStream.TransportState
Enclosing class:
AbstractStream

public abstract static class AbstractStream.TransportState extends Object implements ApplicationThreadDeframer.TransportExecutor, MessageDeframer.Listener
Stream state as used by the transport. This should only be called from the transport thread (except for private interactions with AbstractStream).
  • Field Details

    • DEFAULT_ONREADY_THRESHOLD

      public static final int DEFAULT_ONREADY_THRESHOLD
      The default number of queued bytes for a given stream, below which StreamListener.onReady() will be called.
      See Also:
    • deframer

      private Deframer deframer
    • onReadyLock

      private final Object onReadyLock
    • statsTraceCtx

      private final StatsTraceContext statsTraceCtx
    • transportTracer

      private final TransportTracer transportTracer
    • rawDeframer

      private final MessageDeframer rawDeframer
    • numSentBytesQueued

      private int numSentBytesQueued
      The number of bytes currently queued, waiting to be sent. When this falls below DEFAULT_ONREADY_THRESHOLD, StreamListener.onReady() will be called.
    • allocated

      private boolean allocated
      Indicates the stream has been created on the connection. This implies that the stream is no longer limited by MAX_CONCURRENT_STREAMS.
    • deallocated

      private boolean deallocated
      Indicates that the stream no longer exists for the transport. Implies that the application should be discouraged from sending, because doing so would have no effect.
    • onReadyThreshold

      private int onReadyThreshold
  • Constructor Details

  • Method Details

    • optimizeForDirectExecutor

      final void optimizeForDirectExecutor()
    • setFullStreamDecompressor

      protected void setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)
    • setMaxInboundMessageSize

      final void setMaxInboundMessageSize(int maxSize)
    • listener

      protected abstract StreamListener listener()
      Override this method to provide a stream listener.
    • setOnReadyThreshold

      void setOnReadyThreshold(int numBytes)
      A hint to the stream that specifies how many bytes must be queued before isReady() will return false. A stream may ignore this property if unsupported. This may only be set before any messages are sent.
      Parameters:
      numBytes - The number of bytes that must be queued. Must be a positive integer.
    • messagesAvailable

      public void messagesAvailable(StreamListener.MessageProducer producer)
      Description copied from interface: MessageDeframer.Listener
      Called to deliver the next complete message.
      Specified by:
      messagesAvailable in interface MessageDeframer.Listener
      Parameters:
      producer - single message producer wrapping the message.
    • closeDeframer

      protected final void closeDeframer(boolean stopDelivery)
      Closes the deframer and frees any resources. After this method is called, additional calls will have no effect.

      When stopDelivery is false, the deframer will wait to close until any already queued messages have been delivered.

      The deframer will invoke ApplicationThreadDeframerListener.deframerClosed(boolean) upon closing.

      Parameters:
      stopDelivery - interrupt pending deliveries and close immediately
    • deframe

      protected final void deframe(ReadableBuffer frame)
      Called to parse a received frame and attempt delivery of any completed messages. Must be called from the transport thread.
    • requestMessagesFromDeframer

      private void requestMessagesFromDeframer(int numMessages)
      Called to request the given number of messages from the deframer. May be called from any thread.
    • requestMessagesFromDeframerForTesting

      public final void requestMessagesFromDeframerForTesting(int numMessages)
      Very rarely used. Prefer stream.request() instead of this; this method is only necessary if a stream is not available.
    • getStatsTraceContext

      public final StatsTraceContext getStatsTraceContext()
    • setDecompressor

      protected final void setDecompressor(Decompressor decompressor)
    • isReady

      private boolean isReady()
    • onStreamAllocated

      protected void onStreamAllocated()
      Event handler to be called by the subclass when the stream's headers have passed any connection flow control (i.e., MAX_CONCURRENT_STREAMS). It may call the listener's StreamListener.onReady() handler if appropriate. This must be called from the transport thread, since the listener may be called back directly.
    • onStreamDeallocated

      protected final void onStreamDeallocated()
      Notify that the stream does not exist in a usable state any longer. This causes AbstractStream.isReady() to return false from this point forward.

      This does not generally need to be called explicitly by the transport, as it is handled implicitly by AbstractClientStream and AbstractServerStream.

    • isStreamDeallocated

      protected boolean isStreamDeallocated()
    • onSendingBytes

      private void onSendingBytes(int numBytes)
      Event handler to be called by the subclass when a number of bytes are being queued for sending to the remote endpoint.
      Parameters:
      numBytes - the number of bytes being sent.
    • onSentBytes

      public final void onSentBytes(int numBytes)
      Event handler to be called by the subclass when a number of bytes has been sent to the remote endpoint. May call back the listener's StreamListener.onReady() handler if appropriate. This must be called from the transport thread, since the listener may be called back directly.
      Parameters:
      numBytes - the number of bytes that were sent.
    • getTransportTracer

      protected TransportTracer getTransportTracer()
    • notifyIfReady

      private void notifyIfReady()