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 boolean
allocated
Indicates the stream has been created on the connection.private boolean
deallocated
Indicates that the stream no longer exists for the transport.static int
DEFAULT_ONREADY_THRESHOLD
The default number of queued bytes for a given stream, below whichStreamListener.onReady()
will be called.private Deframer
deframer
private int
numSentBytesQueued
The number of bytes currently queued, waiting to be sent.private java.lang.Object
onReadyLock
private int
onReadyThreshold
private MessageDeframer
rawDeframer
private StatsTraceContext
statsTraceCtx
private TransportTracer
transportTracer
-
Constructor Summary
Constructors Modifier Constructor Description protected
TransportState(int maxMessageSize, StatsTraceContext statsTraceCtx, TransportTracer transportTracer)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
closeDeframer(boolean stopDelivery)
Closes the deframer and frees any resources.protected void
deframe(ReadableBuffer frame)
Called to parse a received frame and attempt delivery of any completed messages.StatsTraceContext
getStatsTraceContext()
protected TransportTracer
getTransportTracer()
private boolean
isReady()
protected boolean
isStreamDeallocated()
protected abstract StreamListener
listener()
Override this method to provide a stream listener.void
messagesAvailable(StreamListener.MessageProducer producer)
Called to deliver the next complete message.private void
notifyIfReady()
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.void
onSentBytes(int numBytes)
Event handler to be called by the subclass when a number of bytes has been sent to the remote endpoint.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).protected void
onStreamDeallocated()
Notify that the stream does not exist in a usable state any longer.(package private) void
optimizeForDirectExecutor()
private void
requestMessagesFromDeframer(int numMessages)
Called to request the given number of messages from the deframer.void
requestMessagesFromDeframerForTesting(int numMessages)
Very rarely used.protected void
setDecompressor(Decompressor decompressor)
protected void
setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)
(package private) void
setMaxInboundMessageSize(int maxSize)
(package private) void
setOnReadyThreshold(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.Listener
Called to deliver the next complete message.- Specified by:
messagesAvailable
in 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
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'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 returnfalse
from this point forward.This does not generally need to be called explicitly by the transport, as it is handled implicitly by
AbstractClientStream
andAbstractServerStream
.
-
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()
-
-