Class TimeoutTask

  • All Implemented Interfaces:
    ITimeoutTask, ITimerTask, java.lang.Runnable

    public class TimeoutTask
    extends java.util.TimerTask
    implements ITimeoutTask
    The implementation of the interface for a registered timeout task that can be queried for timeout or canceled state.
    Author:
    Christopher Mindus
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      booleancancelTimeout()
      Cancels the timeout task.
      longgetRemainingTime()
      Gets the remaining time before timeout.
      longgetStartTime()
      Gets the starting time.
      booleanhasNotifiedTimeout()
      Returns whether timeout notification has been called or not.
      booleanhasTimedOut()
      Verifies if timeout has occurred.
      voidrun()
      Called when timeout occurs.
      • Methods inherited from class java.util.TimerTask

        cancel, scheduledExecutionTime
      • Methods inherited from class java.lang.Object

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

      • getStartTime

        public long getStartTime()
        Gets the starting time.

        Returns the starting time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

        See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).

        Specified by:
        getStartTime in interface ITimerTask
        Returns:
        The difference, measured in milliseconds, between the start time and midnight, January 1, 1970 UTC.
        See Also:
        Date
      • getRemainingTime

        public long getRemainingTime()
        Gets the remaining time before timeout. This value just keeps on counting, even when the timeout has occurred or the task is stopped.
        Specified by:
        getRemainingTime in interface ITimeoutTask
        Returns:
        A time in milliseconds >= zero indicating the remaining timeout time, or < zero if the task has timed out. The return value is Long.MAX_VALUE if the timeout is indefinite.
      • hasTimedOut

        public boolean hasTimedOut()
        Verifies if timeout has occurred.
        Specified by:
        hasTimedOut in interface ITimeoutTask
        Returns:
        true if the task has timed out, false otherwise.
      • hasNotifiedTimeout

        public boolean hasNotifiedTimeout()
        Returns whether timeout notification has been called or not.
        Specified by:
        hasNotifiedTimeout in interface ITimeoutTask
        Returns:
        true if the timeout task has been notified, false otherwise (e.g. task canceled).
      • cancelTimeout

        public boolean cancelTimeout()
        Cancels the timeout task. This call can be done from any thread and will stop any timeout notification of ITimeoutListener.onTimeout().
        Specified by:
        cancelTimeout in interface ITimeoutTask
        Returns:
        true for success, false if already canceled.
      • run

        public void run()
        Called when timeout occurs.
        Specified by:
        run in interface java.lang.Runnable
        Specified by:
        run in class java.util.TimerTask