Class ClientInterceptors.CheckedForwardingClientCall<ReqT,RespT>
- java.lang.Object
-
- io.grpc.ClientCall<ReqT,RespT>
-
- io.grpc.ForwardingClientCall<ReqT,RespT>
-
- io.grpc.ClientInterceptors.CheckedForwardingClientCall<ReqT,RespT>
-
- Enclosing class:
- ClientInterceptors
public abstract static class ClientInterceptors.CheckedForwardingClientCall<ReqT,RespT> extends ForwardingClientCall<ReqT,RespT>
AForwardingClientCall
that delivers exceptions from its start logic to the call listener.ClientCall.start(ClientCall.Listener, Metadata)
should not throw any exception other than those caused by misuse, e.g.,IllegalStateException
.CheckedForwardingClientCall
providescheckedStart()
in which throwing exceptions is allowed.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.grpc.ForwardingClientCall
ForwardingClientCall.SimpleForwardingClientCall<ReqT,RespT>
-
Nested classes/interfaces inherited from class io.grpc.ClientCall
ClientCall.Listener<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
CheckedForwardingClientCall(ClientCall<ReqT,RespT> delegate)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
cancel(String message, Throwable cause)
Prevent any further processing for thisClientCall
.protected abstract void
checkedStart(ClientCall.Listener<RespT> responseListener, Metadata headers)
Subclasses implement the start logic here that would normally belong tostart()
.protected ClientCall<ReqT,RespT>
delegate()
Returns the delegatedClientCall
.Attributes
getAttributes()
Returns additional properties of the call.void
halfClose()
Close the call for request message sending.boolean
isReady()
Iftrue
, indicates that the call is capable of sending additional messages without requiring excessive buffering internally.void
request(int numMessages)
Requests up to the given number of messages from the call to be delivered toClientCall.Listener.onMessage(Object)
.void
setMessageCompression(boolean enabled)
Enables per-message compression, if an encoding type has been negotiated.void
start(ClientCall.Listener<RespT> responseListener, Metadata headers)
Start a call, usingresponseListener
for processing response messages.String
toString()
-
Methods inherited from class io.grpc.ForwardingClientCall
sendMessage
-
-
-
-
Constructor Detail
-
CheckedForwardingClientCall
protected CheckedForwardingClientCall(ClientCall<ReqT,RespT> delegate)
-
-
Method Detail
-
checkedStart
protected abstract void checkedStart(ClientCall.Listener<RespT> responseListener, Metadata headers) throws Exception
Subclasses implement the start logic here that would normally belong tostart()
.Implementation should call
this.delegate().start()
in the normal path. Exceptions may safely be thrown prior to callingthis.delegate().start()
. Such exceptions will be handled byCheckedForwardingClientCall
and be delivered toresponseListener
. Exceptions must not be thrown after callingthis.delegate().start()
, as this can result inClientCall.Listener.onClose(io.grpc.Status, io.grpc.Metadata)
being called multiple times.- Throws:
Exception
-
delegate
protected final ClientCall<ReqT,RespT> delegate()
Description copied from class:ForwardingClientCall
Returns the delegatedClientCall
.- Specified by:
delegate
in classForwardingClientCall<ReqT,RespT>
-
start
public final void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
Description copied from class:ClientCall
Start a call, usingresponseListener
for processing response messages.It must be called prior to any other method on this class, except for
ClientCall.cancel(java.lang.String, java.lang.Throwable)
which may be called at any time.Since
Metadata
is not thread-safe, the caller must not access (read or write)headers
after this point.- Overrides:
start
in classForwardingClientCall<ReqT,RespT>
- Parameters:
responseListener
- receives response messagesheaders
- which can contain extra call metadata, e.g. authentication credentials.
-
request
public void request(int numMessages)
Description copied from class:ClientCall
Requests up to the given number of messages from the call to be delivered toClientCall.Listener.onMessage(Object)
. No additional messages will be delivered.Message delivery is guaranteed to be sequential in the order received. In addition, the listener methods will not be accessed concurrently. While it is not guaranteed that the same thread will always be used, it is guaranteed that only a single thread will access the listener at a time.
If it is desired to bypass inbound flow control, a very large number of messages can be specified (e.g.
Integer.MAX_VALUE
).If called multiple times, the number of messages able to delivered will be the sum of the calls.
This method is safe to call from multiple threads without external synchronization.
- Specified by:
request
in classClientCall<ReqT,RespT>
- Parameters:
numMessages
- the requested number of messages to be delivered to the listener. Must be non-negative.
-
cancel
public void cancel(@Nullable String message, @Nullable Throwable cause)
Description copied from class:ClientCall
Prevent any further processing for thisClientCall
. No further messages may be sent or will be received. The server is informed of cancellations, but may not stop processing the call. Cancellation is permitted even if previouslyClientCall.halfClose()
d. Cancelling an alreadycancel()
edClientCall
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 classClientCall<ReqT,RespT>
- Parameters:
message
- if notnull
, will appear as the description of the CANCELLED statuscause
- if notnull
, will appear as the cause of the CANCELLED status
-
halfClose
public void halfClose()
Description copied from class:ClientCall
Close the call for request message sending. Incoming response messages are unaffected. This should be called when no more messages will be sent from the client.- Specified by:
halfClose
in classClientCall<ReqT,RespT>
-
setMessageCompression
public void setMessageCompression(boolean enabled)
Description copied from class:ClientCall
Enables per-message compression, if an encoding type has been negotiated. If no message encoding has been negotiated, this is a no-op. By default per-message compression is enabled, but may not have any effect if compression is not enabled on the call.- Overrides:
setMessageCompression
in classClientCall<ReqT,RespT>
-
isReady
public boolean isReady()
Description copied from class:ClientCall
Iftrue
, indicates that the call is capable of sending additional messages without requiring excessive buffering internally. This event is just a suggestion and the application is free to ignore it, however doing so may result in excessive buffering within the call.If
false
,ClientCall.Listener.onReady()
will be called afterisReady()
transitions totrue
.If the type of the call is either
MethodDescriptor.MethodType.UNARY
orMethodDescriptor.MethodType.SERVER_STREAMING
, this method may persistently return false. Calls that send exactly one message should not check this method.This abstract class's implementation always returns
true
. Implementations generally override the method.- Overrides:
isReady
in classClientCall<ReqT,RespT>
-
getAttributes
public Attributes getAttributes()
Description copied from class:ClientCall
Returns additional properties of the call. May only be called afterClientCall.Listener.onHeaders(io.grpc.Metadata)
orClientCall.Listener.onClose(io.grpc.Status, io.grpc.Metadata)
. If called prematurely, the implementation may throwIllegalStateException
or return arbitraryAttributes
.- Overrides:
getAttributes
in classClientCall<ReqT,RespT>
- Returns:
- non-
null
attributes
-
-