Class DelayedClientCall<ReqT,RespT>
- java.lang.Object
-
- io.grpc.ClientCall<ReqT,RespT>
-
- io.grpc.internal.DelayedClientCall<ReqT,RespT>
-
- Direct Known Subclasses:
ManagedChannelImpl.RealChannel.PendingCall
public class DelayedClientCall<ReqT,RespT> extends ClientCall<ReqT,RespT>
A call that queues requests before a real call is ready to be delegated to.ClientCallitself doesn't require thread-safety. However, the state ofDelayedCallmay be internally altered by different threads, thus internal synchronization is necessary.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classDelayedClientCall.CloseListenerRunnableprivate static classDelayedClientCall.DelayedListener<RespT>-
Nested classes/interfaces inherited from class io.grpc.ClientCall
ClientCall.Listener<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ExecutorcallExecutorprivate Contextcontextprivate DelayedClientCall.DelayedListener<RespT>delayedListenerprivate Statuserrorprivate java.util.concurrent.ScheduledFuture<?>initialDeadlineMonitorA timer to monitor the initial deadline.private ClientCall.Listener<RespT>listenerNon-nulliff start has been called.private static java.util.logging.Loggerloggerprivate static ClientCall<java.lang.Object,java.lang.Object>NOOP_CALLprivate booleanpassThroughtrueonce realCall is valid and all pending calls have been drained.private java.util.List<java.lang.Runnable>pendingRunnablesprivate ClientCall<ReqT,RespT>realCall
-
Constructor Summary
Constructors Modifier Constructor Description protectedDelayedClientCall(java.util.concurrent.Executor callExecutor, java.util.concurrent.ScheduledExecutorService scheduler, Deadline deadline)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcallCancelled()private voidcancel(Status status, boolean onlyCancelPendingCall)Cancels the call unlessrealCallis set andonlyCancelPendingCallis true.voidcancel(java.lang.String message, java.lang.Throwable cause)Prevent any further processing for thisClientCall.private voiddelayOrExecute(java.lang.Runnable runnable)private voiddrainPendingCalls()Called to transitionpassThroughtotrue.AttributesgetAttributes()Returns additional properties of the call.(package private) ClientCall<ReqT,RespT>getRealCall()voidhalfClose()Close the call for request message sending.private booleanisAbeforeB(Deadline a, Deadline b)booleanisReady()Iftrue, indicates that the call is capable of sending additional messages without requiring excessive buffering internally.voidrequest(int numMessages)Requests up to the given number of messages from the call to be delivered toClientCall.Listener.onMessage(Object).private java.util.concurrent.ScheduledFuture<?>scheduleDeadlineIfNeeded(java.util.concurrent.ScheduledExecutorService scheduler, Deadline deadline)voidsendMessage(ReqT message)Send a request message to the server.java.lang.RunnablesetCall(ClientCall<ReqT,RespT> call)Transfers all pending and future requests and mutations to the given call.voidsetMessageCompression(boolean enable)Enables per-message compression, if an encoding type has been negotiated.private voidsetRealCall(ClientCall<ReqT,RespT> realCall)voidstart(ClientCall.Listener<RespT> listener, Metadata headers)Start a call, usingresponseListenerfor processing response messages.java.lang.StringtoString()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
initialDeadlineMonitor
@Nullable private final java.util.concurrent.ScheduledFuture<?> initialDeadlineMonitor
A timer to monitor the initial deadline. The timer must be cancelled on transition to the real call.
-
callExecutor
private final java.util.concurrent.Executor callExecutor
-
context
private final Context context
-
passThrough
private volatile boolean passThrough
trueonce realCall is valid and all pending calls have been drained.
-
listener
private ClientCall.Listener<RespT> listener
Non-nulliff start has been called. Used to assert methods are called in appropriate order, but also used if an error occurs beforerealCallis set.
-
realCall
private ClientCall<ReqT,RespT> realCall
-
error
private Status error
-
pendingRunnables
private java.util.List<java.lang.Runnable> pendingRunnables
-
delayedListener
private DelayedClientCall.DelayedListener<RespT> delayedListener
-
NOOP_CALL
private static final ClientCall<java.lang.Object,java.lang.Object> NOOP_CALL
-
-
Constructor Detail
-
DelayedClientCall
protected DelayedClientCall(java.util.concurrent.Executor callExecutor, java.util.concurrent.ScheduledExecutorService scheduler, @Nullable Deadline deadline)
-
-
Method Detail
-
scheduleDeadlineIfNeeded
@Nullable private java.util.concurrent.ScheduledFuture<?> scheduleDeadlineIfNeeded(java.util.concurrent.ScheduledExecutorService scheduler, @Nullable Deadline deadline)
-
setCall
public final java.lang.Runnable setCall(ClientCall<ReqT,RespT> call)
Transfers all pending and future requests and mutations to the given call.No-op if either this method or
cancel(java.lang.String, java.lang.Throwable)have already been called.
-
start
public final void start(ClientCall.Listener<RespT> listener, Metadata headers)
Description copied from class:ClientCallStart a call, usingresponseListenerfor 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
Metadatais not thread-safe, the caller must not access (read or write)headersafter this point.- Specified by:
startin classClientCall<ReqT,RespT>- Parameters:
listener- receives response messagesheaders- which can contain extra call metadata, e.g. authentication credentials.
-
cancel
public final void cancel(@Nullable java.lang.String message, @Nullable java.lang.Throwable cause)Description copied from class:ClientCallPrevent 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()edClientCallhas 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 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
-
cancel
private void cancel(Status status, boolean onlyCancelPendingCall)
Cancels the call unlessrealCallis set andonlyCancelPendingCallis true.
-
callCancelled
protected void callCancelled()
-
delayOrExecute
private void delayOrExecute(java.lang.Runnable runnable)
-
drainPendingCalls
private void drainPendingCalls()
Called to transitionpassThroughtotrue. This method is not safe to be called multiple times; the caller must ensure it will only be called once, ever.thislock should not be held when calling this method.
-
setRealCall
private void setRealCall(ClientCall<ReqT,RespT> realCall)
-
getRealCall
final ClientCall<ReqT,RespT> getRealCall()
-
sendMessage
public final void sendMessage(ReqT message)
Description copied from class:ClientCallSend a request message to the server. May be called zero or more times depending on how many messages the server is willing to accept for the operation.- Specified by:
sendMessagein classClientCall<ReqT,RespT>- Parameters:
message- message to be sent to the server.
-
setMessageCompression
public final void setMessageCompression(boolean enable)
Description copied from class:ClientCallEnables 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:
setMessageCompressionin classClientCall<ReqT,RespT>
-
request
public final void request(int numMessages)
Description copied from class:ClientCallRequests 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:
requestin classClientCall<ReqT,RespT>- Parameters:
numMessages- the requested number of messages to be delivered to the listener. Must be non-negative.
-
halfClose
public final void halfClose()
Description copied from class:ClientCallClose 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:
halfClosein classClientCall<ReqT,RespT>
-
isReady
public final boolean isReady()
Description copied from class:ClientCallIftrue, 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.UNARYorMethodDescriptor.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:
isReadyin classClientCall<ReqT,RespT>
-
getAttributes
public final Attributes getAttributes()
Description copied from class:ClientCallReturns 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 throwIllegalStateExceptionor return arbitraryAttributes.- Overrides:
getAttributesin classClientCall<ReqT,RespT>- Returns:
- non-
nullattributes
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-