Enum Class Time

java.lang.Object
java.lang.Enum<Time>
com.linkedin.alpini.base.misc.Time
All Implemented Interfaces:
Serializable, Comparable<Time>, Constable

public enum Time extends Enum<Time>
Utility methods for time travelling and freezing time. This is useful when implementing tests which are dependant upon the passage of time.
  • Enum Constant Details

    • SINGLETON

      public static final Time SINGLETON
  • Method Details

    • values

      public static Time[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Time valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • currentTimeMillis

      public static long currentTimeMillis()
    • nanoTime

      public static long nanoTime()
    • restore

      public static void restore()
    • freeze

      public static void freeze()
    • freeze

      public static void freeze(long frozenTimeMillis, long frozenNano)
    • advance

      public static void advance(long time, TimeUnit unit)
    • systemUTC

      public static Clock systemUTC()
      Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone.

      This clock, rather than systemDefaultZone(), should be used when you need the current instant without the date or time.

      This clock is based on the best available system clock. This may use System.currentTimeMillis(), or a higher resolution clock if one is available.

      Conversion from instant to date or time uses the UTC time-zone.

      The returned implementation is immutable, thread-safe and Serializable. It is equivalent to system(ZoneOffset.UTC).

      Returns:
      a clock that uses the best available system clock in the UTC zone, not null
    • systemDefaultZone

      public static Clock systemDefaultZone()
      Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.

      This clock is based on the best available system clock. This may use System.currentTimeMillis(), or a higher resolution clock if one is available.

      Using this method hard codes a dependency to the default time-zone into your application. It is recommended to avoid this and use a specific time-zone whenever possible. The UTC clock should be used when you need the current instant without the date or time.

      The returned implementation is immutable, thread-safe and Serializable. It is equivalent to system(ZoneId.systemDefault()).

      Returns:
      a clock that uses the best available system clock in the default zone, not null
      See Also:
    • system

      public static Clock system(ZoneId zone)
      Obtains a clock that returns the current instant using best available system clock.

      This clock is based on the best available system clock. This may use System.currentTimeMillis(), or a higher resolution clock if one is available.

      Conversion from instant to date or time uses the specified time-zone.

      The returned implementation is immutable, thread-safe and Serializable.

      Parameters:
      zone - the time-zone to use to convert the instant to date-time, not null
      Returns:
      a clock that uses the best available system clock in the specified zone, not null
    • sleep

      public static void sleep(long milliseconds) throws InterruptedException
      Throws:
      InterruptedException
    • sleep

      public static void sleep(long milliseconds, int nanos) throws InterruptedException
      Throws:
      InterruptedException
    • sleepUninterruptably

      public static void sleepUninterruptably(long milliseconds)
    • sleepInterruptable

      public static boolean sleepInterruptable(long milliseconds)
    • await

      public static boolean await(CountDownLatch latch, long timeout, TimeUnit unit) throws InterruptedException
      Throws:
      InterruptedException
    • await

      public static boolean await(Condition latch, long timeout, TimeUnit unit) throws InterruptedException
      Throws:
      InterruptedException
    • await

      public static boolean await(Time.Awaitable obj, long timeout, TimeUnit unit) throws InterruptedException
      Throws:
      InterruptedException