Class Http2Ping

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<ClientTransport.PingCallback,​java.util.concurrent.Executor> callbacks
      The registered callbacks and the executor used to invoke them.
      private boolean completed
      False until the operation completes, either successfully (other side sent acknowledgement) or unsuccessfully.
      private long data
      The PING frame includes 8 octets of payload data, e.g.
      private java.lang.Throwable failureCause
      If non-null, indicates the ping failed.
      private static java.util.logging.Logger log  
      private long roundTripTimeNanos
      The round-trip time for the ping, in nanoseconds.
      private com.google.common.base.Stopwatch stopwatch
      Used to measure elapsed time.
    • Constructor Summary

      Constructors 
      Constructor Description
      Http2Ping​(long data, com.google.common.base.Stopwatch stopwatch)
      Creates a new ping operation.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCallback​(ClientTransport.PingCallback callback, java.util.concurrent.Executor executor)
      Registers a callback that is invoked when the ping operation completes.
      private static java.lang.Runnable asRunnable​(ClientTransport.PingCallback callback, long roundTripTimeNanos)
      Returns a runnable that, when run, invokes the given callback, providing the given round-trip duration.
      private static java.lang.Runnable asRunnable​(ClientTransport.PingCallback callback, java.lang.Throwable failureCause)
      Returns a runnable that, when run, invokes the given callback, providing the given cause of failure.
      boolean complete()
      Completes this operation successfully.
      private static void doExecute​(java.util.concurrent.Executor executor, java.lang.Runnable runnable)
      Executes the given runnable.
      void failed​(java.lang.Throwable failureCause)
      Completes this operation exceptionally.
      static void notifyFailed​(ClientTransport.PingCallback callback, java.util.concurrent.Executor executor, java.lang.Throwable cause)
      Notifies the given callback that the ping operation failed.
      long payload()
      Returns the expected ping payload for this outstanding operation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static final java.util.logging.Logger log
      • data

        private final long data
        The PING frame includes 8 octets of payload data, e.g. 64 bits.
      • stopwatch

        private final com.google.common.base.Stopwatch stopwatch
        Used to measure elapsed time.
      • callbacks

        private java.util.Map<ClientTransport.PingCallback,​java.util.concurrent.Executor> callbacks
        The registered callbacks and the executor used to invoke them.
      • completed

        private boolean completed
        False until the operation completes, either successfully (other side sent acknowledgement) or unsuccessfully.
      • failureCause

        private java.lang.Throwable failureCause
        If non-null, indicates the ping failed.
      • roundTripTimeNanos

        private long roundTripTimeNanos
        The round-trip time for the ping, in nanoseconds. This value is only meaningful when completed is true and failureCause is null.
    • Constructor Detail

      • 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 Detail

      • addCallback

        public void addCallback​(ClientTransport.PingCallback callback,
                                java.util.concurrent.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​(java.lang.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,
                                        java.util.concurrent.Executor executor,
                                        java.lang.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
      • doExecute

        private static void doExecute​(java.util.concurrent.Executor executor,
                                      java.lang.Runnable runnable)
        Executes the given runnable. This prevents exceptions from propagating so that an exception thrown by one callback won't prevent subsequent callbacks from being executed.
      • asRunnable

        private static java.lang.Runnable asRunnable​(ClientTransport.PingCallback callback,
                                                     long roundTripTimeNanos)
        Returns a runnable that, when run, invokes the given callback, providing the given round-trip duration.
      • asRunnable

        private static java.lang.Runnable asRunnable​(ClientTransport.PingCallback callback,
                                                     java.lang.Throwable failureCause)
        Returns a runnable that, when run, invokes the given callback, providing the given cause of failure.