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 for
ServerStream implementations. Extending classes only need to
implement transportState() and abstractServerStreamSink(). Must only be called
from the sending application thread.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceA sink for outbound operations, separated from the stream simply to avoid name collisions/confusion.protected static classThis should only be called from the transport thread (except for private interactions withAbstractServerStream). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MessageFramerprivate booleanprivate booleanprivate final StatsTraceContext -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractServerStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract AbstractServerStream.SinkSink for transport to be called to perform outbound operations.private voidaddStatusToTrailers(Metadata trailers, Status status) final voidTears down the stream, typically in the event of a timeout.final voidCloses the stream for both reading and writing.final voiddeliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages) Delivers a frame via the transport.protected final MessageFramerframer()The framer to use for sending messages.Attributes describing stream.Gets the authority this stream is addressed to.final booleanisReady()Iftrue, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.final voidsetDecompressor(Decompressor decompressor) Sets the decompressor on the deframer.final voidsetListener(ServerStreamListener serverStreamListener) Sets the server stream listener.voidsetOnReadyThreshold(int numBytes) A hint to the stream that specifies how many bytes must be queued beforeisReady()will return false.The context for recording stats and traces for this stream.protected abstract AbstractServerStream.TransportStateObtain the transport state corresponding to this stream.final voidwriteHeaders(Metadata headers, boolean flush) Writes custom metadata as headers on the response stream sent to the client.Methods inherited from class AbstractStream
endOfMessages, flush, onSendingBytes, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, writeMessageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ServerStream
streamIdMethods inherited from interface Stream
flush, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, writeMessage
-
Field Details
-
framer
-
statsTraceCtx
-
outboundClosed
private boolean outboundClosed -
headersSent
private boolean headersSent
-
-
Constructor Details
-
AbstractServerStream
protected AbstractServerStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx)
-
-
Method Details
-
transportState
Description copied from class:AbstractStreamObtain the transport state corresponding to this stream. Each stream must have its own unique transport state.- Specified by:
transportStatein classAbstractStream
-
abstractServerStreamSink
Sink for transport to be called to perform outbound operations. Each stream must have its own unique sink. -
framer
Description copied from class:AbstractStreamThe framer to use for sending messages.- Specified by:
framerin classAbstractStream
-
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.
-
deliverFrame
public final void deliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages) Description copied from interface:MessageFramer.SinkDelivers a frame via the transport.- Specified by:
deliverFramein interfaceMessageFramer.Sink- Parameters:
frame- a non-empty buffer to deliver ornullif the framer is being closed and there is no data to deliver.endOfStream- whether the frame is the last one for the GRPC streamflush-trueif more data may not be arriving soonnumMessages- the number of messages that this series of frames represents
-
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.
-
addStatusToTrailers
-
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
-
isReady
public final 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.
- Specified by:
isReadyin interfaceStream- Overrides:
isReadyin classAbstractStream
-
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.
-
setListener
Description copied from interface:ServerStreamSets the server stream listener.- Specified by:
setListenerin interfaceServerStream
-
statsTraceContext
Description copied from interface:ServerStreamThe context for recording stats and traces for this stream.- Specified by:
statsTraceContextin 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:
setOnReadyThresholdin interfaceServerStream- Overrides:
setOnReadyThresholdin classAbstractStream- Parameters:
numBytes- The number of bytes that must be queued. Must be a positive integer.
-