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 Summary
FieldsModifier and TypeFieldDescriptionprivate booleanIndicates the stream has been created on the connection.private booleanIndicates that the stream no longer exists for the transport.static final intThe default number of queued bytes for a given stream, below whichStreamListener.onReady()will be called.private Deframerprivate intThe number of bytes currently queued, waiting to be sent.private final Objectprivate intprivate final MessageDeframerprivate final StatsTraceContextprivate final TransportTracer -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTransportState(int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer) -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidcloseDeframer(boolean stopDelivery) Closes the deframer and frees any resources.protected final voiddeframe(ReadableBuffer frame) Called to parse a received frame and attempt delivery of any completed messages.final StatsTraceContextprotected TransportTracerprivate booleanisReady()protected booleanprotected abstract StreamListenerlistener()Override this method to provide a stream listener.voidCalled to deliver the next complete message.private voidprivate voidonSendingBytes(int numBytes) Event handler to be called by the subclass when a number of bytes are being queued for sending to the remote endpoint.final voidonSentBytes(int numBytes) Event handler to be called by the subclass when a number of bytes has been sent to the remote endpoint.protected voidEvent handler to be called by the subclass when the stream's headers have passed any connection flow control (i.e., MAX_CONCURRENT_STREAMS).protected final voidNotify that the stream does not exist in a usable state any longer.(package private) final voidprivate voidrequestMessagesFromDeframer(int numMessages) Called to request the given number of messages from the deframer.final voidrequestMessagesFromDeframerForTesting(int numMessages) Very rarely used.protected final voidsetDecompressor(Decompressor decompressor) protected voidsetFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor) (package private) final voidsetMaxInboundMessageSize(int maxSize) (package private) voidsetOnReadyThreshold(int numBytes) A hint to the stream that specifies how many bytes must be queued beforeisReady()will return false.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ApplicationThreadDeframerListener.TransportExecutor
runOnTransportThreadMethods inherited from interface MessageDeframer.Listener
bytesRead, deframeFailed, deframerClosed
-
Field Details
-
DEFAULT_ONREADY_THRESHOLD
public static final int DEFAULT_ONREADY_THRESHOLDThe default number of queued bytes for a given stream, below whichStreamListener.onReady()will be called.- See Also:
-
deframer
-
onReadyLock
-
statsTraceCtx
-
transportTracer
-
rawDeframer
-
numSentBytesQueued
private int numSentBytesQueuedThe number of bytes currently queued, waiting to be sent. When this falls below DEFAULT_ONREADY_THRESHOLD,StreamListener.onReady()will be called. -
allocated
private boolean allocatedIndicates the stream has been created on the connection. This implies that the stream is no longer limited by MAX_CONCURRENT_STREAMS. -
deallocated
private boolean deallocatedIndicates 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
-
TransportState
protected TransportState(int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer)
-
-
Method Details
-
optimizeForDirectExecutor
final void optimizeForDirectExecutor() -
setFullStreamDecompressor
-
setMaxInboundMessageSize
final void setMaxInboundMessageSize(int maxSize) -
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 beforeisReady()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
Description copied from interface:MessageDeframer.ListenerCalled to deliver the next complete message.- Specified by:
messagesAvailablein interfaceMessageDeframer.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
stopDeliveryis 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
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
-
setDecompressor
-
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'sStreamListener.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 causesAbstractStream.isReady()to returnfalsefrom this point forward.This does not generally need to be called explicitly by the transport, as it is handled implicitly by
AbstractClientStreamandAbstractServerStream. -
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'sStreamListener.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
-
notifyIfReady
private void notifyIfReady()
-