Registers a callback that is invoked when the ping operation completes. If this ping operation is already completed, the callback is invoked immediately. @param callback the callback to invoke @param executor the executor to use
(final ClientTransport.PingCallback callback, Executor executor)
| 92 | * @param executor the executor to use |
| 93 | */ |
| 94 | public void addCallback(final ClientTransport.PingCallback callback, Executor executor) { |
| 95 | Runnable runnable; |
| 96 | synchronized (this) { |
| 97 | if (!completed) { |
| 98 | callbacks.put(callback, executor); |
| 99 | return; |
| 100 | } |
| 101 | // otherwise, invoke callback immediately (but not while holding lock) |
| 102 | runnable = this.failureCause != null ? asRunnable(callback, failureCause) |
| 103 | : asRunnable(callback, roundTripTimeNanos); |
| 104 | } |
| 105 | doExecute(executor, runnable); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the expected ping payload for this outstanding operation. |