Interface TimerStructure

  • All Known Implementing Classes:
    TimerWheels

    public interface TimerStructure
    Interface of the timer task data structure.

    The interface allows different implementations for timer data structures, like tree, heap oder timer wheels. The interface is not 100% abstracted, since the implementation makes use of TimerTask internals (prev and next pointers).

    The timer data structure is not supposed to be thread safe, it is called with proper locking from the timer code.

    Author:
    Jens Wilke
    • Method Detail

      • schedule

        long schedule​(TimerTask task,
                      long time)
        Insert task. Scheduling might be not possible if tasks for the requested time have already be run.
        Returns:
        0, if time is already in the past. Or a positive value indicating the execution time of the timer slot
      • cancelAll

        void cancelAll()
        Cancel all tasks
      • removeNextToRun

        TimerTask removeNextToRun​(long time)
        Return a task that is supposed to execute at the given time or earlier. This also moves the clock hand of the timer structure.

        It may rarely happen that a subsequent method call has an earlier time, in case the operating system schedule delays a thread until the next scheduler event happens.

        Returns:
        a task or null, if no more tasks are scheduled for the given time
      • nextRun

        long nextRun()
        Time of next run, or MAX_VALUE if no more tasks are scheduled