Class Alarm

  • All Implemented Interfaces:
    Disposable

    public class Alarm
    extends Object
    implements Disposable
    Utility class used to execute periodical tasks
    • Constructor Detail

      • Alarm

        public Alarm​(@NotNull
                     String name)
    • Method Detail

      • dispose

        public void dispose()
        Disposes this alarm
        Specified by:
        dispose in interface Disposable
      • addRepeatableRequest

        public void addRepeatableRequest​(Runnable toRun,
                                         long delay,
                                         long repeatDelay)
        Adds repeatable request to the alarm
        Parameters:
        toRun - runnable to execute
        delay - delay before the first start of the runnable (millis)
        repeatDelay - repeat delay (millis)
      • addRequest

        public void addRequest​(Runnable toRun,
                               long delay,
                               boolean repeatable)
        Adds request to the alarm
        Parameters:
        toRun - runnable to execute
        delay - delay before the first start of the runnable (millis)
        repeatable - if true then request will be repeatable, same as: addRepeatableRequest(toRun, delay, delay)
      • cancelAllRequests

        public void cancelAllRequests()
        Cancels all requests added to this alarm
      • cancelRequest

        public void cancelRequest​(Runnable request)
        Cancels specific request added to the alarm
        Parameters:
        request - runnable
      • hasRequests

        public boolean hasRequests()
        Returns true if there are requests added to the alarm
        Returns:
        see above