public abstract class AbstractServerStream extends AbstractStream implements ServerStream, MessageFramer.Sink
ServerStream
implementations. Extending classes only need to
implement transportState()
and abstractServerStreamSink()
. Must only be called
from the sending application thread.Modifier and Type | Class and 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 called from the transport thread (except for private interactions with
AbstractServerStream ). |
Modifier | Constructor and Description |
---|---|
protected |
AbstractServerStream(WritableBufferAllocator bufferAllocator,
StatsTraceContext statsTraceCtx) |
Modifier and Type | Method and Description |
---|---|
protected abstract AbstractServerStream.Sink |
abstractServerStreamSink()
Sink for transport to be called to perform outbound operations.
|
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.
|
String |
getAuthority()
Gets the authority this stream is addressed to.
|
boolean |
isReady()
If
true , indicates that the transport is capable of sending additional messages without
requiring excessive buffering internally. |
void |
request(int numMessages)
Requests up to the given number of messages from the call to be delivered via
StreamListener.messagesAvailable(StreamListener.MessageProducer) . |
void |
setDecompressor(Decompressor decompressor)
Sets the decompressor on the deframer.
|
void |
setListener(ServerStreamListener serverStreamListener)
Sets the server stream listener.
|
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)
Writes custom metadata as headers on the response stream sent to the client.
|
endOfMessages, flush, onSendingBytes, setCompressor, setMessageCompression, writeMessage
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
flush, setCompressor, setMessageCompression, writeMessage
protected AbstractServerStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx)
protected abstract AbstractServerStream.TransportState transportState()
AbstractStream
transportState
in class AbstractStream
protected abstract AbstractServerStream.Sink abstractServerStreamSink()
protected final MessageFramer framer()
AbstractStream
framer
in class AbstractStream
public final void request(int numMessages)
Stream
StreamListener.messagesAvailable(StreamListener.MessageProducer)
. No additional
messages will be delivered. If the stream has a start()
method, it must be called
before requesting messages.public final void writeHeaders(Metadata headers)
ServerStream
Stream.writeMessage(java.io.InputStream)
or ServerStream.close(io.grpc.Status, io.grpc.Metadata)
.writeHeaders
in interface ServerStream
headers
- to send to client.public final void deliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages)
MessageFramer.Sink
deliverFrame
in interface MessageFramer.Sink
frame
- a non-empty buffer to deliver or null
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 representspublic final void close(Status status, Metadata trailers)
ServerStream
Status.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.
close
in interface ServerStream
status
- details of the closuretrailers
- an additional block of metadata to pass to the client on stream closure.public final void cancel(Status status)
ServerStream
cancel
in interface ServerStream
public final boolean isReady()
Stream
true
, indicates that the transport is capable of sending additional messages without
requiring excessive buffering internally. Otherwise, StreamListener.onReady()
will be
called when it turns true
.
This is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the transport.
isReady
in interface Stream
isReady
in class AbstractStream
public final void setDecompressor(Decompressor decompressor)
ServerStream
setDecompressor
in interface ServerStream
decompressor
- the decompressor to use.public Attributes getAttributes()
ServerStream
ServerCall.getAttributes()
.getAttributes
in interface ServerStream
public String getAuthority()
ServerStream
getAuthority
in interface ServerStream
null
if not available.public final void setListener(ServerStreamListener serverStreamListener)
ServerStream
setListener
in interface ServerStream
public StatsTraceContext statsTraceContext()
ServerStream
statsTraceContext
in interface ServerStream
Copyright © 2018. All rights reserved.