Package io.grpc.internal
Class AbstractServerStream
- java.lang.Object
-
- io.grpc.internal.AbstractStream
-
- io.grpc.internal.AbstractServerStream
-
- All Implemented Interfaces:
MessageFramer.Sink
,ServerStream
,Stream
- Direct Known Subclasses:
NettyServerStream
,ServletServerStream
,ServletServerStream
public abstract class AbstractServerStream extends AbstractStream implements ServerStream, MessageFramer.Sink
Abstract base class forServerStream
implementations. Extending classes only need to implementtransportState()
andabstractServerStreamSink()
. Must only be called from the sending application thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
AbstractServerStream.Sink
A sink for outbound operations, separated from the stream simply to avoid name collisions/confusion.protected static class
AbstractServerStream.TransportState
This should only be called from the transport thread (except for private interactions withAbstractServerStream
).
-
Field Summary
Fields Modifier and Type Field Description private MessageFramer
framer
private boolean
headersSent
private boolean
outboundClosed
private StatsTraceContext
statsTraceCtx
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractServerStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractServerStream.Sink
abstractServerStreamSink()
Sink for transport to be called to perform outbound operations.private void
addStatusToTrailers(Metadata trailers, Status status)
void
cancel(Status status)
Tears down the stream, typically in the event of a timeout.void
close(Status status, Metadata trailers)
Closes the stream for both reading and writing.void
deliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages)
Delivers a frame via the transport.protected MessageFramer
framer()
The framer to use for sending messages.Attributes
getAttributes()
Attributes describing stream.java.lang.String
getAuthority()
Gets the authority this stream is addressed to.boolean
isReady()
Iftrue
, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.void
setDecompressor(Decompressor decompressor)
Sets the decompressor on the deframer.void
setListener(ServerStreamListener serverStreamListener)
Sets the server stream listener.void
setOnReadyThreshold(int numBytes)
A hint to the stream that specifies how many bytes must be queued beforeisReady()
will return false.StatsTraceContext
statsTraceContext()
The context for recording stats and traces for this stream.protected abstract AbstractServerStream.TransportState
transportState()
Obtain the transport state corresponding to this stream.void
writeHeaders(Metadata headers, boolean flush)
Writes custom metadata as headers on the response stream sent to the client.-
Methods inherited from class io.grpc.internal.AbstractStream
endOfMessages, flush, onSendingBytes, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, writeMessage
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.grpc.internal.ServerStream
streamId
-
Methods inherited from interface io.grpc.internal.Stream
flush, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, writeMessage
-
-
-
-
Field Detail
-
framer
private final MessageFramer framer
-
statsTraceCtx
private final StatsTraceContext statsTraceCtx
-
outboundClosed
private boolean outboundClosed
-
headersSent
private boolean headersSent
-
-
Constructor Detail
-
AbstractServerStream
protected AbstractServerStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx)
-
-
Method Detail
-
transportState
protected abstract AbstractServerStream.TransportState transportState()
Description copied from class:AbstractStream
Obtain the transport state corresponding to this stream. Each stream must have its own unique transport state.- Specified by:
transportState
in classAbstractStream
-
abstractServerStreamSink
protected abstract AbstractServerStream.Sink abstractServerStreamSink()
Sink for transport to be called to perform outbound operations. Each stream must have its own unique sink.
-
framer
protected final MessageFramer framer()
Description copied from class:AbstractStream
The framer to use for sending messages.- Specified by:
framer
in classAbstractStream
-
writeHeaders
public final 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.
-
deliverFrame
public final void deliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages)
Description copied from interface:MessageFramer.Sink
Delivers a frame via the transport.- Specified by:
deliverFrame
in interfaceMessageFramer.Sink
- Parameters:
frame
- a non-empty buffer to deliver ornull
if the framer is being closed and there is no data to deliver.endOfStream
- whether the frame is the last one for the GRPC streamflush
-true
if more data may not be arriving soonnumMessages
- the number of messages that this series of frames represents
-
close
public final 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.
-
cancel
public final 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
-
isReady
public final 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.
- Specified by:
isReady
in interfaceStream
- Overrides:
isReady
in classAbstractStream
-
setDecompressor
public final 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.
-
setListener
public final void setListener(ServerStreamListener serverStreamListener)
Description copied from interface:ServerStream
Sets the server stream listener.- Specified by:
setListener
in interfaceServerStream
-
statsTraceContext
public StatsTraceContext statsTraceContext()
Description copied from interface:ServerStream
The context for recording stats and traces for this stream.- Specified by:
statsTraceContext
in interfaceServerStream
-
setOnReadyThreshold
public 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 before any messages are sent.- Specified by:
setOnReadyThreshold
in interfaceServerStream
- Overrides:
setOnReadyThreshold
in classAbstractStream
- Parameters:
numBytes
- The number of bytes that must be queued. Must be a positive integer.
-
-