Class ClientCalls.CallToStreamObserverAdapter<ReqT>
- All Implemented Interfaces:
StreamObserver<ReqT>
- Enclosing class:
ClientCalls
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate final ClientCall<ReqT, ?> private booleanprivate booleanprivate intprivate Runnableprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionCallToStreamObserverAdapter(ClientCall<ReqT, ?> call, boolean streamingResponse) -
Method Summary
Modifier and TypeMethodDescriptionvoidPrevent any further processing for thisClientCallStreamObserver.voidDisables automatic flow control where a token is returned to the peer after a call to the 'inbound'StreamObserver.onNext(Object)has completed.voiddisableAutoRequestWithInitial(int request) Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)unless it isrequest()ed.private voidfreeze()booleanisReady()Iftrue, indicates that the observer is capable of sending additional messages without requiring excessive buffering internally.voidReceives a notification of successful stream completion.voidReceives a terminating error from the stream.voidReceives a value from the stream.voidrequest(int count) Requests the peer to producecountmore messages to be delivered to the 'inbound'StreamObserver.voidsetMessageCompression(boolean enable) Sets message compression for subsequent calls toStreamObserver.onNext(V).voidsetOnReadyHandler(Runnable onReadyHandler) Set aRunnablethat will be executed every time the streamClientCallStreamObserver.isReady()state changes fromfalsetotrue.
-
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:StreamObserverReceives 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:StreamObserverReceives 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
onErrorno further calls to any method are allowed.tshould be aStatusExceptionorStatusRuntimeException, but otherThrowabletypes are possible. Callers should generally convert from aStatusviaStatus.asException()orStatus.asRuntimeException(). Implementations should generally convert to aStatusviaStatus.fromThrowable(Throwable).- Parameters:
t- the error occurred on the stream
-
onCompleted
public void onCompleted()Description copied from interface:StreamObserverReceives 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
onCompletedno further calls to any method are allowed. -
isReady
public boolean isReady()Description copied from class:ClientCallStreamObserverIftrue, 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:
isReadyin classClientCallStreamObserver<ReqT>
-
setOnReadyHandler
Description copied from class:ClientCallStreamObserverSet aRunnablethat will be executed every time the streamClientCallStreamObserver.isReady()state changes fromfalsetotrue. 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() == falsewithin this callback. Handle "spurious" notifications by checkingisReady()'s current value instead of assuming it is nowtrue. IfisReady() == falsethe normal expectations apply, so there would be anotheronReadyHandlercallback.- Specified by:
setOnReadyHandlerin classClientCallStreamObserver<ReqT>- Parameters:
onReadyHandler- to call when peer is ready to receive more messages.
-
disableAutoInboundFlowControl
public void disableAutoInboundFlowControl()Description copied from class:CallStreamObserverDisables 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.UNARYoperations on both the client and server.MethodDescriptor.MethodType.CLIENT_STREAMINGoperations on the client.MethodDescriptor.MethodType.SERVER_STREAMINGoperations 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:
disableAutoInboundFlowControlin classCallStreamObserver<ReqT>
-
disableAutoRequestWithInitial
public void disableAutoRequestWithInitial(int request) Description copied from class:ClientCallStreamObserverSwaps 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:
disableAutoRequestWithInitialin classClientCallStreamObserver<ReqT>
-
request
public void request(int count) Description copied from class:ClientCallStreamObserverRequests the peer to producecountmore messages to be delivered to the 'inbound'StreamObserver.This method is safe to call from multiple threads without external synchronization.
- Specified by:
requestin classClientCallStreamObserver<ReqT>- Parameters:
count- more messages
-
setMessageCompression
public void setMessageCompression(boolean enable) Description copied from class:ClientCallStreamObserverSets message compression for subsequent calls toStreamObserver.onNext(V).- Specified by:
setMessageCompressionin classClientCallStreamObserver<ReqT>- Parameters:
enable- whether to enable compression.
-
cancel
Description copied from class:ClientCallStreamObserverPrevent 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()edClientCallStreamObserverhas 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:
cancelin 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
-