Class Http2Ping

java.lang.Object
io.grpc.internal.Http2Ping

public class Http2Ping extends Object
Represents an outstanding PING operation on an HTTP/2 channel. This can be used by HTTP/2-based transports to implement ClientTransport.ping(io.grpc.internal.ClientTransport.PingCallback, java.util.concurrent.Executor).

A typical transport need only support one outstanding ping at a time. So, if a ping is requested while an operation is already in progress, the given callback is notified when the existing operation completes.

  • Constructor Details

    • Http2Ping

      public Http2Ping(long data, com.google.common.base.Stopwatch stopwatch)
      Creates a new ping operation. The caller is responsible for sending a ping on an HTTP/2 channel using the given payload. The caller is also responsible for starting the stopwatch when the PING frame is sent.
      Parameters:
      data - the ping payload
      stopwatch - a stopwatch for measuring round-trip time
  • Method Details

    • addCallback

      public void addCallback(ClientTransport.PingCallback callback, Executor executor)
      Registers a callback that is invoked when the ping operation completes. If this ping operation is already completed, the callback is invoked immediately.
      Parameters:
      callback - the callback to invoke
      executor - the executor to use
    • payload

      public long payload()
      Returns the expected ping payload for this outstanding operation.
      Returns:
      the expected payload for this outstanding ping
    • complete

      public boolean complete()
      Completes this operation successfully. The stopwatch given during construction is used to measure the elapsed time. Registered callbacks are invoked and provided the measured elapsed time.
      Returns:
      true if the operation is marked as complete; false if it was already complete
    • failed

      public void failed(Throwable failureCause)
      Completes this operation exceptionally. Registered callbacks are invoked and provided the given throwable as the cause of failure.
      Parameters:
      failureCause - the cause of failure
    • notifyFailed

      public static void notifyFailed(ClientTransport.PingCallback callback, Executor executor, Throwable cause)
      Notifies the given callback that the ping operation failed.
      Parameters:
      callback - the callback
      executor - the executor used to invoke the callback
      cause - the cause of failure