Class DefaultTimerService<K>

  • Type Parameters:
    K - Type of the key
    All Implemented Interfaces:
    TimerService<K>

    public class DefaultTimerService<K>
    extends Object
    implements TimerService<K>
    Service to register timeouts for a given key. The timeouts are identified by a ticket so that newly registered timeouts for the same key can be distinguished from older timeouts.
    • Constructor Detail

      • DefaultTimerService

        public DefaultTimerService​(ScheduledExecutorService scheduledExecutorService,
                                   long shutdownTimeout)
    • Method Detail

      • start

        public void start​(TimeoutListener<K> initialTimeoutListener)
        Description copied from interface: TimerService
        Starts this timer service.
        Specified by:
        start in interface TimerService<K>
        Parameters:
        initialTimeoutListener - listener for timeouts that have fired
      • stop

        public void stop()
        Description copied from interface: TimerService
        Stops this timer service.
        Specified by:
        stop in interface TimerService<K>
      • registerTimeout

        public void registerTimeout​(K key,
                                    long delay,
                                    TimeUnit unit)
        Description copied from interface: TimerService
        Register a timeout for the given key which shall occur in the given delay.
        Specified by:
        registerTimeout in interface TimerService<K>
        Parameters:
        key - for which to register the timeout
        delay - until the timeout
        unit - of the timeout delay
      • unregisterTimeout

        public void unregisterTimeout​(K key)
        Description copied from interface: TimerService
        Unregister the timeout for the given key.
        Specified by:
        unregisterTimeout in interface TimerService<K>
        Parameters:
        key - for which to unregister the timeout
      • unregisterAllTimeouts

        protected void unregisterAllTimeouts()
        Unregister all timeouts.
      • isValid

        public boolean isValid​(K key,
                               UUID ticket)
        Description copied from interface: TimerService
        Check whether the timeout for the given key and ticket is still valid (not yet unregistered and not yet overwritten).
        Specified by:
        isValid in interface TimerService<K>
        Parameters:
        key - for which to check the timeout
        ticket - of the timeout
        Returns:
        True if the timeout ticket is still valid; otherwise false