Class ClientCalls.CallToStreamObserverAdapter<ReqT>
- All Implemented Interfaces:
StreamObserver<ReqT>
- Enclosing class:
ClientCalls
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private final ClientCall
<ReqT, ?> private boolean
private boolean
private int
private Runnable
private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionCallToStreamObserverAdapter
(ClientCall<ReqT, ?> call, boolean streamingResponse) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Prevent any further processing for thisClientCallStreamObserver
.void
Disables automatic flow control where a token is returned to the peer after a call to the 'inbound'StreamObserver.onNext(Object)
has completed.void
disableAutoRequestWithInitial
(int request) Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)
unless it isrequest()
ed.private void
freeze()
boolean
isReady()
Iftrue
, indicates that the observer is capable of sending additional messages without requiring excessive buffering internally.void
Receives a notification of successful stream completion.void
Receives a terminating error from the stream.void
Receives a value from the stream.void
request
(int count) Requests the peer to producecount
more messages to be delivered to the 'inbound'StreamObserver
.void
setMessageCompression
(boolean enable) Sets message compression for subsequent calls toStreamObserver.onNext(V)
.void
setOnReadyHandler
(Runnable onReadyHandler) Set aRunnable
that will be executed every time the streamClientCallStreamObserver.isReady()
state changes fromfalse
totrue
.
-
Field Details
-
frozen
private boolean frozen -
call
-
streamingResponse
private final boolean streamingResponse -
onReadyHandler
-
initialRequest
private int initialRequest -
autoRequestEnabled
private boolean autoRequestEnabled -
aborted
private boolean aborted -
completed
private boolean completed
-
-
Constructor Details
-
CallToStreamObserverAdapter
CallToStreamObserverAdapter(ClientCall<ReqT, ?> call, boolean streamingResponse)
-
-
Method Details
-
freeze
private void freeze() -
onNext
Description copied from interface:StreamObserver
Receives a value from the stream.Can be called many times but is never called after
StreamObserver.onError(Throwable)
orStreamObserver.onCompleted()
are called.Unary calls must invoke onNext at most once. Clients may invoke onNext at most once for server streaming calls, but may receive many onNext callbacks. Servers may invoke onNext at most once for client streaming calls, but may receive many onNext callbacks.
If an exception is thrown by an implementation the caller is expected to terminate the stream by calling
StreamObserver.onError(Throwable)
with the caught exception prior to propagating it.- Parameters:
value
- the value passed to the stream
-
onError
Description copied from interface:StreamObserver
Receives a terminating error from the stream.May only be called once and if called it must be the last method called. In particular if an exception is thrown by an implementation of
onError
no further calls to any method are allowed.t
should be aStatusException
orStatusRuntimeException
, but otherThrowable
types are possible. Callers should generally convert from aStatus
viaStatus.asException()
orStatus.asRuntimeException()
. Implementations should generally convert to aStatus
viaStatus.fromThrowable(Throwable)
.- Parameters:
t
- the error occurred on the stream
-
onCompleted
public void onCompleted()Description copied from interface:StreamObserver
Receives a notification of successful stream completion.May only be called once and if called it must be the last method called. In particular if an exception is thrown by an implementation of
onCompleted
no further calls to any method are allowed. -
isReady
public boolean isReady()Description copied from class:ClientCallStreamObserver
Iftrue
, indicates that the observer is capable of sending additional messages without requiring excessive buffering internally. This value is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the observer.If
false
, the runnable passed toClientCallStreamObserver.setOnReadyHandler(java.lang.Runnable)
will be called afterisReady()
transitions totrue
.- Specified by:
isReady
in classClientCallStreamObserver<ReqT>
-
setOnReadyHandler
Description copied from class:ClientCallStreamObserver
Set aRunnable
that will be executed every time the streamClientCallStreamObserver.isReady()
state changes fromfalse
totrue
. While it is not guaranteed that the same thread will always be used to execute theRunnable
, it is guaranteed that executions are serialized with calls to the 'inbound'StreamObserver
.May only be called during
ClientResponseObserver.beforeStart(io.grpc.stub.ClientCallStreamObserver<ReqT>)
.Because there is a processing delay to deliver this notification, it is possible for concurrent writes to cause
isReady() == false
within this callback. Handle "spurious" notifications by checkingisReady()
's current value instead of assuming it is nowtrue
. IfisReady() == false
the normal expectations apply, so there would be anotheronReadyHandler
callback.- Specified by:
setOnReadyHandler
in classClientCallStreamObserver<ReqT>
- Parameters:
onReadyHandler
- to call when peer is ready to receive more messages.
-
disableAutoInboundFlowControl
public void disableAutoInboundFlowControl()Description copied from class:CallStreamObserver
Disables automatic flow control where a token is returned to the peer after a call to the 'inbound'StreamObserver.onNext(Object)
has completed. If disabled an application must make explicit calls toCallStreamObserver.request(int)
to receive messages.On client-side this method may only be called during
ClientResponseObserver.beforeStart(io.grpc.stub.ClientCallStreamObserver<ReqT>)
. On server-side it may only be called during the initial call to the application, before the service returns itsStreamObserver
.Note that for cases where the runtime knows that only one inbound message is allowed calling this method will have no effect and the runtime will always permit one and only one message. This is true for:
MethodDescriptor.MethodType.UNARY
operations on both the client and server.MethodDescriptor.MethodType.CLIENT_STREAMING
operations on the client.MethodDescriptor.MethodType.SERVER_STREAMING
operations on the server.
This API is being replaced, but is not yet deprecated. On server-side it being replaced with
ServerCallStreamObserver.disableAutoRequest()
. On client-sidedisableAutoRequestWithInitial(1)
.- Specified by:
disableAutoInboundFlowControl
in classCallStreamObserver<ReqT>
-
disableAutoRequestWithInitial
public void disableAutoRequestWithInitial(int request) Description copied from class:ClientCallStreamObserver
Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)
unless it isrequest()
ed. Sincerequest()
may not be called before the call is started, a number of initial requests may be specified.This method may only be called during
ClientResponseObserver.beforeStart()
.- Overrides:
disableAutoRequestWithInitial
in classClientCallStreamObserver<ReqT>
-
request
public void request(int count) Description copied from class:ClientCallStreamObserver
Requests the peer to producecount
more messages to be delivered to the 'inbound'StreamObserver
.This method is safe to call from multiple threads without external synchronization.
- Specified by:
request
in classClientCallStreamObserver<ReqT>
- Parameters:
count
- more messages
-
setMessageCompression
public void setMessageCompression(boolean enable) Description copied from class:ClientCallStreamObserver
Sets message compression for subsequent calls toStreamObserver.onNext(V)
.- Specified by:
setMessageCompression
in classClientCallStreamObserver<ReqT>
- Parameters:
enable
- whether to enable compression.
-
cancel
Description copied from class:ClientCallStreamObserver
Prevent any further processing for thisClientCallStreamObserver
. No further messages will be received. The server is informed of cancellations, but may not stop processing the call. Cancelling an alreadycancel()
edClientCallStreamObserver
has no effect.No other methods on this class can be called after this method has been called.
It is recommended that at least one of the arguments to be non-
null
, to provide useful debug information. Both argument being null may log warnings and result in suboptimal performance. Also note that the provided information will not be sent to the server.- Specified by:
cancel
in classClientCallStreamObserver<ReqT>
- Parameters:
message
- if notnull
, will appear as the description of the CANCELLED statuscause
- if notnull
, will appear as the cause of the CANCELLED status
-