Class CyclicTimeout

  • All Implemented Interfaces:
    org.eclipse.jetty.util.component.Destroyable

    public abstract class CyclicTimeout
    extends Object
    implements org.eclipse.jetty.util.component.Destroyable

    An abstract implementation of a timeout.

    Subclasses should implement onTimeoutExpired().

    This implementation is optimised assuming that the timeout will mostly be cancelled and then reused with a similar value.

    • Constructor Detail

      • CyclicTimeout

        public CyclicTimeout​(org.eclipse.jetty.util.thread.Scheduler scheduler)
        Parameters:
        scheduler - A scheduler used to schedule wakeups
    • Method Detail

      • getScheduler

        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
      • schedule

        public boolean schedule​(long delay,
                                TimeUnit units)
        Schedules a timeout, even if already set, cancelled or expired.
        Parameters:
        delay - The period of time before the timeout expires.
        units - The unit of time of the period.
        Returns:
        true if the timer was already set.
      • cancel

        public boolean cancel()

        Cancels this CyclicTimeout so that it won't expire.

        After being cancelled, this CyclicTimeout can be scheduled again.

        Returns:
        true if this CyclicTimeout was scheduled to expire
        See Also:
        destroy()
      • onTimeoutExpired

        public abstract void onTimeoutExpired()

        Invoked when the timeout expires.

      • destroy

        public void destroy()

        Destroys this CyclicTimeout.

        After being destroyed, this CyclicTimeout is not used anymore.

        Specified by:
        destroy in interface org.eclipse.jetty.util.component.Destroyable