Package io.grpc.inprocess
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 java.lang.Object implements ServerStream
-
-
Field Summary
Fields Modifier and Type Field Description private StatusclientNotifyStatusprivate MetadataclientNotifyTrailersprivate java.util.ArrayDeque<StreamListener.MessageProducer>clientReceiveQueueprivate intclientRequestedprivate ClientStreamListenerclientStreamListenerprivate booleanclosedprivate intoutboundSeqNo(package private) StatsTraceContextstatsTraceCtxprivate SynchronizationContextsyncContext
-
Constructor Summary
Constructors Constructor Description InProcessServerStream(MethodDescriptor<?,?> method, Metadata headers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel(Status status)Tears down the stream, typically in the event of a timeout.private voidclientCancelled(Status status)private booleanclientRequested(int numMessages)Client requested more messages.voidclose(Status status, Metadata trailers)Closes the stream for both reading and writing.voidflush()Flushes any internally buffered messages to the remote end-point.AttributesgetAttributes()Attributes describing stream.java.lang.StringgetAuthority()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 methodvoidoptimizeForDirectExecutor()Provides 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.StatsTraceContextstatsTraceContext()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(java.io.InputStream message)Writes a message payload to the remote end-point.
-
-
-
Field Detail
-
statsTraceCtx
final StatsTraceContext statsTraceCtx
-
clientStreamListener
private ClientStreamListener clientStreamListener
-
syncContext
private final SynchronizationContext syncContext
-
clientRequested
private int clientRequested
-
clientReceiveQueue
private java.util.ArrayDeque<StreamListener.MessageProducer> clientReceiveQueue
-
clientNotifyStatus
private Status clientNotifyStatus
-
clientNotifyTrailers
private Metadata clientNotifyTrailers
-
closed
private boolean closed
-
outboundSeqNo
private int outboundSeqNo
-
-
Constructor Detail
-
InProcessServerStream
InProcessServerStream(MethodDescriptor<?,?> method, Metadata headers)
-
-
Method Detail
-
setListener
private void setListener(ClientStreamListener listener)
-
setListener
public void setListener(ServerStreamListener serverStreamListener)
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
private void clientCancelled(Status status)
-
writeMessage
public void writeMessage(java.io.InputStream message)
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 void flush()
Description copied from interface:StreamFlushes any internally buffered messages to the remote end-point.
-
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
public void writeHeaders(Metadata headers, boolean flush)
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(java.io.InputStream)orServerStream.close(io.grpc.Status, io.grpc.Metadata).- Specified by:
writeHeadersin interfaceServerStream- Parameters:
headers- to send to client.
-
close
public void close(Status status, Metadata trailers)
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
private void notifyClientClose(Status status, Metadata trailers)
clientStream.serverClosed() must be called before this method
-
cancel
public void cancel(Status status)
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
private boolean internalCancel(Status clientStatus)
-
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
public void setCompressor(Compressor compressor)
Description copied from interface:StreamSets the compressor on the framer.- Specified by:
setCompressorin interfaceStream- Parameters:
compressor- the compressor to use
-
setDecompressor
public void setDecompressor(Decompressor decompressor)
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
public Attributes 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
public java.lang.String 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
public StatsTraceContext 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.
-
-