Module stormpot
Package stormpot

Class Timeout

java.lang.Object
stormpot.Timeout

public final class Timeout extends Object
A Timeout represents the maximum amount of time a caller is willing to wait for a blocking operation to complete.

Timeouts are independent of their units, so two timeouts of equivalent duration but constructed in different units, will be equal to each other and work exactly the same.

Timeouts are also independent of "calendar time" in the sense that they represent and work as a duration of absolute time. In other words, timeouts do not grow or shrink with passing leap seconds or daylight savings time adjustments.

Author:
Chris Vest
  • Constructor Details

    • Timeout

      public Timeout(long timeout, TimeUnit unit)
      Construct a new timeout with the given value and unit. The unit cannot be null, but the timeout value is unrestricted. The meaning of a negative timeout value is specific to the implementation of the use site, but typically means that no amount of blocking or waiting is tolerated.
      Parameters:
      timeout - A numerical value for the timeout. Can be zero or negative, though the meaning is implementation specific.
      unit - The unit of the timeout value. Never null.
    • Timeout

      public Timeout(Duration duration)
      Construct a new timeout with the given duration. An exception will be thrown if the duration cannot be converted to a nanosecond quantity. The duration also cannot be null. Apart from these two, there are no restrictions on the duration.
      Parameters:
      duration - A duration to use for the timeout.
  • Method Details

    • getTimeout

      public long getTimeout()
      Get the timeout value in terms of the unit.
      Returns:
      A numerical value of the timeout. Possibly zero or negative.
    • getUnit

      public TimeUnit getUnit()
      Get the unit for the timeout value.
      Returns:
      The TimeUnit of the timeout value. Never null.
    • getTimeoutInBaseUnit

      public long getTimeoutInBaseUnit()
      Get the timeout value in terms of the base unit.
      Returns:
      A numerical value of the timeout. Possibly zero or negative.
    • getBaseUnit

      public TimeUnit getBaseUnit()
      Get the unit of precision for the underlying clock.
      Returns:
      TimeUnit The unit of precision used by the clock in this Timeout.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Timeouts of equivalent duration are equal, even if they were constructed with different units.
      Overrides:
      equals in class Object
      Returns:
      true if this Timeout value is equal to the given Timeout value, false otherwise.