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 Status
clientNotifyStatus
private Metadata
clientNotifyTrailers
private java.util.ArrayDeque<StreamListener.MessageProducer>
clientReceiveQueue
private int
clientRequested
private ClientStreamListener
clientStreamListener
private boolean
closed
private int
outboundSeqNo
(package private) StatsTraceContext
statsTraceCtx
private SynchronizationContext
syncContext
-
Constructor Summary
Constructors Constructor Description InProcessServerStream(MethodDescriptor<?,?> method, Metadata headers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel(Status status)
Tears down the stream, typically in the event of a timeout.private void
clientCancelled(Status status)
private boolean
clientRequested(int numMessages)
Client requested more messages.void
close(Status status, Metadata trailers)
Closes the stream for both reading and writing.void
flush()
Flushes any internally buffered messages to the remote end-point.Attributes
getAttributes()
Attributes describing stream.java.lang.String
getAuthority()
Gets the authority this stream is addressed to.private boolean
internalCancel(Status clientStatus)
boolean
isReady()
Iftrue
, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.private void
notifyClientClose(Status status, Metadata trailers)
clientStream.serverClosed() must be called before this methodvoid
optimizeForDirectExecutor()
Provides a hint that directExecutor is being used by the listener for callbacks to the application.void
request(int numMessages)
Requests up to the given number of messages from the call to be delivered viaStreamListener.messagesAvailable(StreamListener.MessageProducer)
.void
setCompressor(Compressor compressor)
Sets the compressor on the framer.void
setDecompressor(Decompressor decompressor)
Sets the decompressor on the deframer.private void
setListener(ClientStreamListener listener)
void
setListener(ServerStreamListener serverStreamListener)
Sets the server stream listener.void
setMessageCompression(boolean enable)
Enables per-message compression, if an encoding type has been negotiated.void
setOnReadyThreshold(int numBytes)
A hint to the stream that specifies how many bytes must be queued beforeStream.isReady()
will return false.StatsTraceContext
statsTraceContext()
The context for recording stats and traces for this stream.int
streamId()
The HTTP/2 stream id, or-1
if not supported.void
writeHeaders(Metadata headers, boolean flush)
Writes custom metadata as headers on the response stream sent to the client.void
writeMessage(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:ServerStream
Sets the server stream listener.- Specified by:
setListener
in interfaceServerStream
-
request
public 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.
-
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: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 void flush()
Description copied from interface:Stream
Flushes any internally buffered messages to the remote end-point.
-
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.
-
writeHeaders
public void writeHeaders(Metadata headers, boolean flush)
Description copied from interface:ServerStream
Writes 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:
writeHeaders
in interfaceServerStream
- Parameters:
headers
- to send to client.
-
close
public void close(Status status, Metadata trailers)
Description copied from interface:ServerStream
Closes the stream for both reading and writing. A status code ofStatus.Code.OK
implies 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:
close
in 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:ServerStream
Tears down the stream, typically in the event of a timeout. This method may be called multiple times and from any thread.- Specified by:
cancel
in interfaceServerStream
-
internalCancel
private boolean internalCancel(Status clientStatus)
-
setMessageCompression
public 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
-
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
-
setCompressor
public void setCompressor(Compressor compressor)
Description copied from interface:Stream
Sets the compressor on the framer.- Specified by:
setCompressor
in interfaceStream
- Parameters:
compressor
- the compressor to use
-
setDecompressor
public void setDecompressor(Decompressor decompressor)
Description copied from interface:ServerStream
Sets the decompressor on the deframer. If the transport does not support compression, this may do nothing.- Specified by:
setDecompressor
in interfaceServerStream
- Parameters:
decompressor
- the decompressor to use.
-
getAttributes
public Attributes getAttributes()
Description copied from interface:ServerStream
Attributes describing stream. This is inherited from the transport attributes, and used as the basis ofServerCall.getAttributes()
.- Specified by:
getAttributes
in interfaceServerStream
- Returns:
- Attributes container
-
getAuthority
public java.lang.String getAuthority()
Description copied from interface:ServerStream
Gets the authority this stream is addressed to.- Specified by:
getAuthority
in interfaceServerStream
- Returns:
- the authority string.
null
if not available.
-
statsTraceContext
public StatsTraceContext statsTraceContext()
Description copied from interface:ServerStream
The context for recording stats and traces for this stream.- Specified by:
statsTraceContext
in interfaceServerStream
-
streamId
public int streamId()
Description copied from interface:ServerStream
The HTTP/2 stream id, or-1
if not supported.- Specified by:
streamId
in interfaceServerStream
-
setOnReadyThreshold
public void setOnReadyThreshold(int numBytes)
Description copied from interface:ServerStream
A 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:
setOnReadyThreshold
in interfaceServerStream
- Parameters:
numBytes
- The number of bytes that must be queued. Must be a positive integer.
-
-