Package io.grpc.internal
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 java.lang.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 withAbstractStream).
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallocatedIndicates the stream has been created on the connection.private booleandeallocatedIndicates that the stream no longer exists for the transport.static intDEFAULT_ONREADY_THRESHOLDThe default number of queued bytes for a given stream, below whichStreamListener.onReady()will be called.private Deframerdeframerprivate intnumSentBytesQueuedThe number of bytes currently queued, waiting to be sent.private java.lang.ObjectonReadyLockprivate intonReadyThresholdprivate MessageDeframerrawDeframerprivate StatsTraceContextstatsTraceCtxprivate TransportTracertransportTracer
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransportState(int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcloseDeframer(boolean stopDelivery)Closes the deframer and frees any resources.protected voiddeframe(ReadableBuffer frame)Called to parse a received frame and attempt delivery of any completed messages.StatsTraceContextgetStatsTraceContext()protected TransportTracergetTransportTracer()private booleanisReady()protected booleanisStreamDeallocated()protected abstract StreamListenerlistener()Override this method to provide a stream listener.voidmessagesAvailable(StreamListener.MessageProducer producer)Called to deliver the next complete message.private voidnotifyIfReady()private 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.voidonSentBytes(int numBytes)Event handler to be called by the subclass when a number of bytes has been sent to the remote endpoint.protected voidonStreamAllocated()Event handler to be called by the subclass when the stream's headers have passed any connection flow control (i.e., MAX_CONCURRENT_STREAMS).protected voidonStreamDeallocated()Notify that the stream does not exist in a usable state any longer.(package private) voidoptimizeForDirectExecutor()private voidrequestMessagesFromDeframer(int numMessages)Called to request the given number of messages from the deframer.voidrequestMessagesFromDeframerForTesting(int numMessages)Very rarely used.protected voidsetDecompressor(Decompressor decompressor)protected voidsetFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)(package private) 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.grpc.internal.ApplicationThreadDeframerListener.TransportExecutor
runOnTransportThread
-
Methods inherited from interface io.grpc.internal.MessageDeframer.Listener
bytesRead, deframeFailed, deframerClosed
-
-
-
-
Field Detail
-
DEFAULT_ONREADY_THRESHOLD
public static final int DEFAULT_ONREADY_THRESHOLD
The default number of queued bytes for a given stream, below whichStreamListener.onReady()will be called.- See Also:
- Constant Field Values
-
deframer
private Deframer deframer
-
onReadyLock
private final java.lang.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 Detail
-
TransportState
protected TransportState(int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer)
-
-
Method Detail
-
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 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
public void messagesAvailable(StreamListener.MessageProducer producer)
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
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'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
protected TransportTracer getTransportTracer()
-
notifyIfReady
private void notifyIfReady()
-
-