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 classStream state as used by the transport. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidCloses the underlying framer.final voidflush()Flushes any internally buffered messages to the remote end-point.protected abstract Framerframer()The framer to use for sending messages.booleanisReady()Iftrue, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.protected final 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.voidProvides a hint that directExecutor is being used by the listener for callbacks to the application.final voidrequest(int numMessages) Requests up to the given number of messages from the call to be delivered viaStreamListener.messagesAvailable(StreamListener.MessageProducer).final voidsetCompressor(Compressor compressor) Sets the compressor on the framer.final voidsetMessageCompression(boolean enable) Enables per-message compression, if an encoding type has been negotiated.protected voidsetOnReadyThreshold(int numBytes) A hint to the stream that specifies how many bytes must be queued beforeisReady()will return false.protected abstract AbstractStream.TransportStateObtain the transport state corresponding to this stream.final voidwriteMessage(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:StreamProvides 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:
optimizeForDirectExecutorin interfaceStream
-
setMessageCompression
public final void setMessageCompression(boolean enable) Description copied from interface:StreamEnables 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:
setMessageCompressionin interfaceStream
-
request
public final void request(int numMessages) Description copied from interface:StreamRequests 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:StreamWrites 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 areKnownLengthto 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:
writeMessagein interfaceStream- Parameters:
message- stream containing the serialized message to be sent
-
flush
public final void flush()Description copied from interface:StreamFlushes 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:StreamSets the compressor on the framer.- Specified by:
setCompressorin interfaceStream- Parameters:
compressor- the compressor to use
-
isReady
public boolean isReady()Description copied from interface:StreamIftrue, 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.
-