Package io.grpc.internal
Class AbstractClientStream
- java.lang.Object
-
- io.grpc.internal.AbstractStream
-
- io.grpc.internal.AbstractClientStream
-
- All Implemented Interfaces:
ClientStream,MessageFramer.Sink,Stream
- Direct Known Subclasses:
NettyClientStream
public abstract class AbstractClientStream extends AbstractStream implements ClientStream, MessageFramer.Sink
The abstract base class forClientStreamimplementations. Extending classes only need to implementtransportState()andabstractClientStreamSink(). Must only be called from the sending application thread.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAbstractClientStream.GetFramerprotected static interfaceAbstractClientStream.SinkA sink for outbound operations, separated from the stream simply to avoid name collisions/confusion.protected static classAbstractClientStream.TransportStateThis should only be called from the transport thread.
-
Field Summary
Fields Modifier and Type Field Description private booleancancelledWhether cancel() has been called.private Framerframerprivate Metadataheadersprivate static java.util.logging.Loggerlogprivate booleanshouldBeCountedForInUseprivate TransportTracertransportTracerprivate booleanuseGet
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractClientStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx, TransportTracer transportTracer, Metadata headers, CallOptions callOptions, boolean useGet)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractClientStream.SinkabstractClientStreamSink()Sink for transport to be called to perform outbound operations.voidappendTimeoutInsight(InsightBuilder insight)Append information that will be included in the locally generated DEADLINE_EXCEEDED errors to the givenInsightBuilder, in order to tell the user about the state of the stream so that they can better diagnose the cause of the error.voidcancel(Status reason)Abnormally terminates the stream.voiddeliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush, int numMessages)Delivers a frame via the transport.protected Framerframer()The framer to use for sending messages.protected TransportTracergetTransportTracer()voidhalfClose()Closes the local side of this stream and flushes any remaining messages.booleanisReady()Iftrue, indicates that the transport is capable of sending additional messages without requiring excessive buffering internally.voidsetDeadline(Deadline deadline)Sets the effective deadline of the RPC.voidsetDecompressorRegistry(DecompressorRegistry decompressorRegistry)Sets the registry to find a decompressor for the framer.voidsetFullStreamDecompression(boolean fullStreamDecompression)Enables full-stream decompression, allowing the client stream to useGzipInflatingBufferto decode inbound GZIP compressed streams.voidsetMaxInboundMessageSize(int maxSize)Sets the max size accepted from the remote endpoint.voidsetMaxOutboundMessageSize(int maxSize)Sets the max size sent to the remote endpoint.booleanshouldBeCountedForInUse()Returns true if this stream should be counted when determining the in-use state of the transport.voidstart(ClientStreamListener listener)Starts stream.protected abstract AbstractClientStream.TransportStatetransportState()Obtain the transport state corresponding to this stream.-
Methods inherited from class io.grpc.internal.AbstractStream
endOfMessages, flush, onSendingBytes, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, setOnReadyThreshold, 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.ClientStream
getAttributes, setAuthority
-
Methods inherited from interface io.grpc.internal.Stream
flush, optimizeForDirectExecutor, request, setCompressor, setMessageCompression, writeMessage
-
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
transportTracer
private final TransportTracer transportTracer
-
framer
private final Framer framer
-
shouldBeCountedForInUse
private final boolean shouldBeCountedForInUse
-
useGet
private final boolean useGet
-
headers
private Metadata headers
-
cancelled
private volatile boolean cancelled
Whether cancel() has been called. This is not strictly necessary, but removes the delay between cancel() being called and isReady() beginning to return false, since cancel is commonly processed asynchronously.
-
-
Constructor Detail
-
AbstractClientStream
protected AbstractClientStream(WritableBufferAllocator bufferAllocator, StatsTraceContext statsTraceCtx, TransportTracer transportTracer, Metadata headers, CallOptions callOptions, boolean useGet)
-
-
Method Detail
-
setDeadline
public void setDeadline(Deadline deadline)
Description copied from interface:ClientStreamSets the effective deadline of the RPC.- Specified by:
setDeadlinein interfaceClientStream
-
setMaxOutboundMessageSize
public void setMaxOutboundMessageSize(int maxSize)
Description copied from interface:ClientStreamSets the max size sent to the remote endpoint.- Specified by:
setMaxOutboundMessageSizein interfaceClientStream
-
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int maxSize)
Description copied from interface:ClientStreamSets the max size accepted from the remote endpoint.- Specified by:
setMaxInboundMessageSizein interfaceClientStream
-
setFullStreamDecompression
public final void setFullStreamDecompression(boolean fullStreamDecompression)
Description copied from interface:ClientStreamEnables full-stream decompression, allowing the client stream to useGzipInflatingBufferto decode inbound GZIP compressed streams.- Specified by:
setFullStreamDecompressionin interfaceClientStream
-
setDecompressorRegistry
public final void setDecompressorRegistry(DecompressorRegistry decompressorRegistry)
Description copied from interface:ClientStreamSets the registry to find a decompressor for the framer. May only be called beforeClientStream.start(io.grpc.internal.ClientStreamListener). If the transport does not support compression, this may do nothing.- Specified by:
setDecompressorRegistryin interfaceClientStream- Parameters:
decompressorRegistry- the registry of decompressors for decoding responses
-
transportState
protected abstract AbstractClientStream.TransportState transportState()
Obtain the transport state corresponding to this stream. Each stream must have its own unique transport state.- Specified by:
transportStatein classAbstractStream
-
start
public final void start(ClientStreamListener listener)
Description copied from interface:ClientStreamStarts stream. This method may only be called once. It is safe to do latent initialization of the stream up untilClientStream.start(io.grpc.internal.ClientStreamListener)is called.This method should not throw any exceptions.
- Specified by:
startin interfaceClientStream- Parameters:
listener- non-nulllistener of stream events
-
abstractClientStreamSink
protected abstract AbstractClientStream.Sink abstractClientStreamSink()
Sink for transport to be called to perform outbound operations. Each stream must have its own unique sink.
-
framer
protected final Framer framer()
Description copied from class:AbstractStreamThe framer to use for sending messages.- Specified by:
framerin classAbstractStream
-
shouldBeCountedForInUse
public final boolean shouldBeCountedForInUse()
Returns true if this stream should be counted when determining the in-use state of the transport.
-
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
-
halfClose
public final void halfClose()
Description copied from interface:ClientStreamCloses the local side of this stream and flushes any remaining messages. After this is called, no further messages may be sent on this stream, but additional messages may be received until the remote end-point is closed. This method may only be called once, and only afterClientStream.start(io.grpc.internal.ClientStreamListener).- Specified by:
halfClosein interfaceClientStream
-
cancel
public final void cancel(Status reason)
Description copied from interface:ClientStreamAbnormally terminates the stream. After calling this method, no further messages will be sent or received, however it may still be possible to receive buffered messages for a brief period untilClientStreamListener.closed(io.grpc.Status, io.grpc.internal.ClientStreamListener.RpcProgress, io.grpc.Metadata)is called. This method may only be called afterClientStream.start(io.grpc.internal.ClientStreamListener), but else is safe to be called at any time and multiple times and from any thread.- Specified by:
cancelin interfaceClientStream- Parameters:
reason- must be non-OK
-
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
-
appendTimeoutInsight
public final void appendTimeoutInsight(InsightBuilder insight)
Description copied from interface:ClientStreamAppend information that will be included in the locally generated DEADLINE_EXCEEDED errors to the givenInsightBuilder, in order to tell the user about the state of the stream so that they can better diagnose the cause of the error.- Specified by:
appendTimeoutInsightin interfaceClientStream
-
getTransportTracer
protected TransportTracer getTransportTracer()
-
-