IdT
- the type of the stream identifierpublic abstract class AbstractServerStream<IdT> extends AbstractStream<IdT> implements ServerStream
ServerStream
implementations.AbstractStream.Phase
DEFAULT_ONREADY_THRESHOLD
Modifier | Constructor and Description |
---|---|
protected |
AbstractServerStream(WritableBufferAllocator bufferAllocator) |
Modifier and Type | Method and Description |
---|---|
void |
abortStream(Status status,
boolean notifyClient)
Aborts the stream with an error status, cleans up resources and notifies the listener if
necessary.
|
void |
close(Status status,
Metadata.Trailers trailers)
Closes the stream for both reading and writing.
|
void |
complete()
Indicates the stream is considered completely closed and there is no further opportunity for
error.
|
protected void |
deframeFailed(Throwable cause)
Called when a
AbstractStream.deframe(ReadableBuffer, boolean) operation failed. |
void |
inboundDataReceived(ReadableBuffer frame,
boolean endOfStream)
Called in the network thread to process the content of an inbound DATA frame from the client.
|
protected void |
internalSendFrame(WritableBuffer frame,
boolean endOfStream,
boolean flush)
Sends an outbound frame to the remote end point.
|
protected abstract void |
internalSendHeaders(Metadata.Headers headers)
Sends response headers to the remote end points.
|
boolean |
isClosed()
Whether the stream is fully closed.
|
protected ServerStreamListener |
listener()
Override this method to provide a stream listener.
|
protected void |
receiveMessage(InputStream is)
Handles a message that was just deframed.
|
protected void |
remoteEndClosed()
Called when the remote end half-closes the stream.
|
protected abstract void |
sendFrame(WritableBuffer frame,
boolean endOfStream,
boolean flush)
Sends an outbound frame to the remote end point.
|
protected abstract void |
sendTrailers(Metadata.Trailers trailers,
boolean headersSent)
Sends trailers to the remote end point.
|
void |
setListener(ServerStreamListener listener)
Sets the listener to receive notifications.
|
void |
writeHeaders(Metadata.Headers headers)
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.
|
canReceive, canSend, closeDeframer, deframe, dispose, flush, getOnReadyThreshold, id, inboundDeliveryPaused, isDeframerStalled, isReady, onSendingBytes, onSentBytes, onStreamAllocated, requestMessagesFromDeframer, returnProcessedBytes, toString, toStringHelper
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
cancel
protected AbstractServerStream(WritableBufferAllocator bufferAllocator)
public final void setListener(ServerStreamListener listener)
protected ServerStreamListener listener()
AbstractStream
listener
in class AbstractStream<IdT>
protected void receiveMessage(InputStream is)
AbstractStream
receiveMessage
in class AbstractStream<IdT>
is
- the stream containing the messagepublic final void writeHeaders(Metadata.Headers headers)
ServerStream
Stream.writeMessage(java.io.InputStream)
or ServerStream.close(io.grpc.Status, io.grpc.Metadata.Trailers)
.writeHeaders
in interface ServerStream
headers
- to send to client.public final void writeMessage(InputStream message)
Stream
KnownLength
to improve efficiency. This method will always return immediately
and will not wait for the write to complete.
When the write is "accepted" by the transport, the given callback (if provided) will be called. The definition of what it means to be "accepted" is up to the transport implementation, but this is a general indication that the transport is capable of handling more out-bound data on the stream. If the stream/connection is closed for any reason before the write could be accepted, the callback will never be invoked.
writeMessage
in interface Stream
writeMessage
in class AbstractStream<IdT>
message
- stream containing the serialized message to be sentpublic final void close(Status status, Metadata.Trailers trailers)
ServerStream
Status.Code.OK
implies normal termination of the
stream. Any other value implies abnormal termination.close
in interface ServerStream
status
- details of the closuretrailers
- an additional block of metadata to pass to the client on stream closure.public void inboundDataReceived(ReadableBuffer frame, boolean endOfStream)
frame
- the inbound HTTP/2 DATA frame. If this buffer is not used immediately, it must
be retained.endOfStream
- true
if no more data will be received on the stream.protected final void deframeFailed(Throwable cause)
AbstractStream
AbstractStream.deframe(ReadableBuffer, boolean)
operation failed.deframeFailed
in class AbstractStream<IdT>
cause
- the actual failureprotected final void internalSendFrame(WritableBuffer frame, boolean endOfStream, boolean flush)
AbstractStream
internalSendFrame
in class AbstractStream<IdT>
frame
- a buffer containing the chunk of data to be sent.endOfStream
- if true
indicates that no more data will be sent on the stream by
this endpoint.flush
- true
if more data may not be arriving soonprotected abstract void internalSendHeaders(Metadata.Headers headers)
headers
- the headers to be sent to client.protected abstract void sendFrame(WritableBuffer frame, boolean endOfStream, boolean flush)
frame
- a buffer containing the chunk of data to be sent.endOfStream
- if true
indicates that no more data will be sent on the stream by
this endpoint.flush
- true
if more data may not be arriving soonprotected abstract void sendTrailers(Metadata.Trailers trailers, boolean headersSent)
trailers
- metadata to be sent to end pointheadersSent
- true
if response headers have already been sent.public void complete()
closed()
if it was not already done by abortStream(io.grpc.Status, boolean)
. Note that it is expected that either closed()
or abortStream()
was previously called, since closed()
is required for a normal stream closure and
abortStream()
for abnormal.protected final void remoteEndClosed()
remoteEndClosed
in class AbstractStream<IdT>
public final void abortStream(Status status, boolean notifyClient)
Unlike close(Status, Metadata.Trailers)
, this method is only called from the
transport. The transport should use this method instead of close(Status)
for internal
errors to prevent exposing unexpected states and exceptions to the application.
status
- the error status. Must not be Status.OK
.notifyClient
- true
if the stream is still writable and you want to notify the
client about stream closure and send the statuspublic boolean isClosed()
AbstractStream
inboundPhase
and outboundPhase
are mutated in different threads. Tests must account
for thread coordination when calling.isClosed
in class AbstractStream<IdT>