Class InProcessTransport.InProcessStream.InProcessServerStream
java.lang.Object
io.grpc.inprocess.InProcessTransport.InProcessStream.InProcessServerStream
- All Implemented Interfaces:
ServerStream, Stream
- Enclosing class:
InProcessTransport.InProcessStream
private class InProcessTransport.InProcessStream.InProcessServerStream
extends Object
implements ServerStream
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Statusprivate Metadataprivate ArrayDeque<StreamListener.MessageProducer> private intprivate ClientStreamListenerprivate booleanprivate int(package private) final StatsTraceContextprivate final SynchronizationContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTears down the stream, typically in the event of a timeout.private voidclientCancelled(Status status) private booleanclientRequested(int numMessages) Client requested more messages.voidCloses the stream for both reading and writing.voidflush()Flushes any internally buffered messages to the remote end-point.Attributes describing stream.Gets the authority this stream is addressed to.private booleaninternalCancel(Status clientStatus) booleanisReady()Iftrue, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.private voidnotifyClientClose(Status status, Metadata trailers) clientStream.serverClosed() must be called before this methodvoidProvides a hint that directExecutor is being used by the listener for callbacks to the application.voidrequest(int numMessages) Requests up to the given number of messages from the call to be delivered viaStreamListener.messagesAvailable(StreamListener.MessageProducer).voidsetCompressor(Compressor compressor) Sets the compressor on the framer.voidsetDecompressor(Decompressor decompressor) Sets the decompressor on the deframer.private voidsetListener(ClientStreamListener listener) voidsetListener(ServerStreamListener serverStreamListener) Sets the server stream listener.voidsetMessageCompression(boolean enable) Enables per-message compression, if an encoding type has been negotiated.voidsetOnReadyThreshold(int numBytes) A hint to the stream that specifies how many bytes must be queued beforeStream.isReady()will return false.The context for recording stats and traces for this stream.intstreamId()The HTTP/2 stream id, or-1if not supported.voidwriteHeaders(Metadata headers, boolean flush) Writes custom metadata as headers on the response stream sent to the client.voidwriteMessage(InputStream message) Writes a message payload to the remote end-point.
-
Field Details
-
statsTraceCtx
-
clientStreamListener
-
syncContext
-
clientRequested
private int clientRequested -
clientReceiveQueue
-
clientNotifyStatus
-
clientNotifyTrailers
-
closed
private boolean closed -
outboundSeqNo
private int outboundSeqNo
-
-
Constructor Details
-
InProcessServerStream
InProcessServerStream(MethodDescriptor<?, ?> method, Metadata headers)
-
-
Method Details
-
setListener
-
setListener
Description copied from interface:ServerStreamSets the server stream listener.- Specified by:
setListenerin interfaceServerStream
-
request
public 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. -
clientRequested
private boolean clientRequested(int numMessages) Client requested more messages.- Returns:
- whether onReady should be called on the server
-
clientCancelled
-
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
-
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.
-
writeHeaders
Description copied from interface:ServerStreamWrites custom metadata as headers on the response stream sent to the client. This method may only be called once and cannot be called after calls toStream.writeMessage(InputStream)orServerStream.close(Status, Metadata).- Specified by:
writeHeadersin interfaceServerStream- Parameters:
headers- to send to client.
-
close
Description copied from interface:ServerStreamCloses the stream for both reading and writing. A status code ofStatus.Code.OKimplies normal termination of the stream. Any other value implies abnormal termination.Attempts to read from or write to the stream after closing should be ignored by implementations, and should not throw exceptions.
- Specified by:
closein interfaceServerStream- Parameters:
status- details of the closuretrailers- an additional block of metadata to pass to the client on stream closure.
-
notifyClientClose
-
cancel
Description copied from interface:ServerStreamTears down the stream, typically in the event of a timeout. This method may be called multiple times and from any thread.- Specified by:
cancelin interfaceServerStream
-
internalCancel
-
setMessageCompression
public 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
-
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
-
setCompressor
Description copied from interface:StreamSets the compressor on the framer.- Specified by:
setCompressorin interfaceStream- Parameters:
compressor- the compressor to use
-
setDecompressor
Description copied from interface:ServerStreamSets the decompressor on the deframer. If the transport does not support compression, this may do nothing.- Specified by:
setDecompressorin interfaceServerStream- Parameters:
decompressor- the decompressor to use.
-
getAttributes
Description copied from interface:ServerStreamAttributes describing stream. This is inherited from the transport attributes, and used as the basis ofServerCall.getAttributes().- Specified by:
getAttributesin interfaceServerStream- Returns:
- Attributes container
-
getAuthority
Description copied from interface:ServerStreamGets the authority this stream is addressed to.- Specified by:
getAuthorityin interfaceServerStream- Returns:
- the authority string.
nullif not available.
-
statsTraceContext
Description copied from interface:ServerStreamThe context for recording stats and traces for this stream.- Specified by:
statsTraceContextin interfaceServerStream
-
streamId
public int streamId()Description copied from interface:ServerStreamThe HTTP/2 stream id, or-1if not supported.- Specified by:
streamIdin interfaceServerStream
-
setOnReadyThreshold
public void setOnReadyThreshold(int numBytes) Description copied from interface:ServerStreamA hint to the stream that specifies how many bytes must be queued beforeStream.isReady()will return false. A stream may ignore this property if unsupported. This may only be set during stream initialization before any messages are set.- Specified by:
setOnReadyThresholdin interfaceServerStream- Parameters:
numBytes- The number of bytes that must be queued. Must be a positive integer.
-