Package io.grpc.internal
Class AbstractStream
java.lang.Object
io.grpc.internal.AbstractStream
- All Implemented Interfaces:
Stream
- Direct Known Subclasses:
AbstractClientStream
,AbstractServerStream
The stream and stream state as used by the application. Must only be called from the sending
application thread.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Stream state as used by the transport. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
Closes the underlying framer.final void
flush()
Flushes any internally buffered messages to the remote end-point.protected abstract Framer
framer()
The framer to use for sending messages.boolean
isReady()
Iftrue
, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.protected final 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
Provides a hint that directExecutor is being used by the listener for callbacks to the application.final void
request
(int numMessages) Requests up to the given number of messages from the call to be delivered viaStreamListener.messagesAvailable(StreamListener.MessageProducer)
.final void
setCompressor
(Compressor compressor) Sets the compressor on the framer.final void
setMessageCompression
(boolean enable) Enables per-message compression, if an encoding type has been negotiated.protected void
setOnReadyThreshold
(int numBytes) A hint to the stream that specifies how many bytes must be queued beforeisReady()
will return false.protected abstract AbstractStream.TransportState
Obtain the transport state corresponding to this stream.final void
writeMessage
(InputStream message) Writes a message payload to the remote end-point.
-
Constructor Details
-
AbstractStream
public AbstractStream()
-
-
Method Details
-
framer
The framer to use for sending messages. -
transportState
Obtain the transport state corresponding to this stream. Each stream must have its own unique transport state. -
optimizeForDirectExecutor
public void optimizeForDirectExecutor()Description copied from interface:Stream
Provides a hint that directExecutor is being used by the listener for callbacks to the application. No action is required. There is no requirement that this method actually matches the executor used.- Specified by:
optimizeForDirectExecutor
in interfaceStream
-
setMessageCompression
public final void setMessageCompression(boolean enable) Description copied from interface:Stream
Enables per-message compression, if an encoding type has been negotiated. If no message encoding has been negotiated, this is a no-op. By default per-message compression is enabled, but may not have any effect if compression is not enabled on the call.- Specified by:
setMessageCompression
in interfaceStream
-
request
public final void request(int numMessages) Description copied from interface:Stream
Requests up to the given number of messages from the call to be delivered viaStreamListener.messagesAvailable(StreamListener.MessageProducer)
. No additional messages will be delivered. If the stream has astart()
method, it must be called before requesting messages. -
writeMessage
Description copied from interface:Stream
Writes a message payload to the remote end-point. The bytes from the stream are immediately read by the Transport. Where possible callers should use streams that areKnownLength
to improve efficiency. This method will always return immediately and will not wait for the write to complete. If the stream has astart()
method, it must be called before writing any messages.It is recommended that the caller consult
Stream.isReady()
before calling this method to avoid excessive buffering in the transport.This method takes ownership of the InputStream, and implementations are responsible for calling
InputStream.close()
.- Specified by:
writeMessage
in interfaceStream
- Parameters:
message
- stream containing the serialized message to be sent
-
flush
public final void flush()Description copied from interface:Stream
Flushes any internally buffered messages to the remote end-point. -
setOnReadyThreshold
protected 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 during stream initialization before any messages are set.- Parameters:
numBytes
- The number of bytes that must be queued. Must be a positive integer.
-
endOfMessages
protected final void endOfMessages()Closes the underlying framer. Should be called when the outgoing stream is gracefully closed (half closure on client; closure on server). -
setCompressor
Description copied from interface:Stream
Sets the compressor on the framer.- Specified by:
setCompressor
in interfaceStream
- Parameters:
compressor
- the compressor to use
-
isReady
public boolean isReady()Description copied from interface:Stream
Iftrue
, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally. Otherwise,StreamListener.onReady()
will be called when it turnstrue
.This is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the transport.
-
onSendingBytes
protected final 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.
-