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 Object
implements ServerStream
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Status
private Metadata
private ArrayDeque
<StreamListener.MessageProducer> private int
private ClientStreamListener
private boolean
private int
(package private) final StatsTraceContext
private final SynchronizationContext
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Closes the stream for both reading and writing.void
flush()
Flushes any internally buffered messages to the remote end-point.Attributes describing stream.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
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.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
(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: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
-
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 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
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
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
clientStream.serverClosed() must be called before this method -
cancel
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
-
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
Description copied from interface:Stream
Sets the compressor on the framer.- Specified by:
setCompressor
in interfaceStream
- Parameters:
compressor
- the compressor to use
-
setDecompressor
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
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
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
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.
-