public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT> implements ServerStream
ServerStream implementations.AbstractStream.PhaseDEFAULT_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()
Gets the listener to this stream.
|
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,
int length)
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, setOnReadyThreshold, toString, toStringHelperprotected AbstractServerStream(WritableBufferAllocator bufferAllocator)
public final void setListener(ServerStreamListener listener)
protected ServerStreamListener listener()
AbstractStreamlistener in class AbstractStream<IdT>protected void receiveMessage(InputStream is)
AbstractStreamreceiveMessage in class AbstractStream<IdT>is - the stream containing the messagepublic void writeHeaders(Metadata.Headers headers)
ServerStreamStream#writePayload
or #close.writeHeaders in interface ServerStreamheaders - to send to client.public final void writeMessage(InputStream message, int length)
StreamWhen 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 StreamwriteMessage in class AbstractStream<IdT>message - stream containing the serialized message to be sentlength - the length of the InputStream.public final void close(Status status, Metadata.Trailers trailers)
ServerStreamStatus.Code.OK implies normal termination of the
stream. Any other value implies abnormal termination.close in interface ServerStreamstatus - 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)
AbstractStreamAbstractStream.deframe(ReadableBuffer, boolean) operation failed.deframeFailed in class AbstractStream<IdT>cause - the actual failureprotected final void internalSendFrame(WritableBuffer frame, boolean endOfStream, boolean flush)
AbstractStreaminternalSendFrame 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()
AbstractStreaminboundPhase and outboundPhase are mutated in different threads. Tests must account
for thread coordination when calling.isClosed in class AbstractStream<IdT>