Class TimeoutTimer


  • public class TimeoutTimer
    extends java.lang.Object
    Helps figuring out how much time is left from a particular (initial) timeout.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeoutTimer​(java.time.Duration initialTimeout)
      Creates a new instance of the TimeoutTimer class.
      TimeoutTimer​(java.time.Duration initialTimeout, java.util.function.Supplier<java.lang.Long> getNanos)
      Creates a new instance of the TimeoutTimer class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.time.Duration getElapsed()
      Returns a Duration of the time elapsed in Nanoseconds.
      java.time.Duration getRemaining()
      Calculates how much time is left of the original timeout.
      boolean hasRemaining()
      Returns true if there is time remaining.
      void reset​(java.time.Duration timeout)
      Reset the timeout so that the original amount of time is remaining.
      java.lang.String toString()  
      void zero()
      Adjust the time so that the is no time remaining.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TimeoutTimer

        public TimeoutTimer​(java.time.Duration initialTimeout)
        Creates a new instance of the TimeoutTimer class.
        Parameters:
        initialTimeout - The initial timeout.
      • TimeoutTimer

        public TimeoutTimer​(java.time.Duration initialTimeout,
                            java.util.function.Supplier<java.lang.Long> getNanos)
        Creates a new instance of the TimeoutTimer class.
        Parameters:
        initialTimeout - The initial timeout.
        getNanos - The supplier of nanoseconds.
    • Method Detail

      • getRemaining

        public java.time.Duration getRemaining()
        Calculates how much time is left of the original timeout.
        Returns:
        The remaining time.
      • getElapsed

        public java.time.Duration getElapsed()
        Returns a Duration of the time elapsed in Nanoseconds.
        Returns:
        The elapsed time.
      • hasRemaining

        public boolean hasRemaining()
        Returns true if there is time remaining.
        Returns:
        False if there is no time remaining from the given timeout.
      • reset

        public void reset​(java.time.Duration timeout)
        Reset the timeout so that the original amount of time is remaining. While it is safe to call this concurrently with getRemaining(), the value returned by getRemaining() may be wrong. A synchronized block is NOT required to avoid this.
        Parameters:
        timeout - The duration from now which should be placed on the timer.
      • zero

        public void zero()
        Adjust the time so that the is no time remaining.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object