Class Scheduler.Worker

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  Scheduler.Worker.PeriodicTask
      Holds state and logic to calculate when the next delayed invocation of this task has to happen (accounting for clock drifts).
    • Constructor Summary

      Constructors 
      Constructor Description
      Worker()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      long now​(@NonNull java.util.concurrent.TimeUnit unit)
      Returns the 'current time' of the Worker in the specified time unit.
      @NonNull Disposable schedule​(@NonNull java.lang.Runnable run)
      Schedules a Runnable for execution without any time delay.
      abstract @NonNull Disposable schedule​(@NonNull java.lang.Runnable run, long delay, @NonNull java.util.concurrent.TimeUnit unit)
      Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.
      @NonNull Disposable schedulePeriodically​(@NonNull java.lang.Runnable run, long initialDelay, long period, @NonNull java.util.concurrent.TimeUnit unit)
      Schedules a periodic execution of the given task with the given initial time delay and repeat period.
      • Methods inherited from class java.lang.Object

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

      • Worker

        public Worker()
    • Method Detail

      • schedule

        @NonNull
        public @NonNull Disposable schedule​(@NonNull
                                            @NonNull java.lang.Runnable run)
        Schedules a Runnable for execution without any time delay.

        The default implementation delegates to schedule(Runnable, long, TimeUnit).

        Parameters:
        run - Runnable to schedule
        Returns:
        a Disposable to be able to unsubscribe the action (cancel it if not executed)
        Throws:
        java.lang.NullPointerException - if run is null
      • schedule

        @NonNull
        public abstract @NonNull Disposable schedule​(@NonNull
                                                     @NonNull java.lang.Runnable run,
                                                     long delay,
                                                     @NonNull
                                                     @NonNull java.util.concurrent.TimeUnit unit)
        Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.

        Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the schedule(Runnable) was called.

        Parameters:
        run - the Runnable to schedule
        delay - time to "wait" before executing the action; non-positive values indicate an non-delayed schedule
        unit - the time unit of delayTime
        Returns:
        a Disposable to be able to unsubscribe the action (cancel it if not executed)
        Throws:
        java.lang.NullPointerException - if run or unit is null
      • schedulePeriodically

        @NonNull
        public @NonNull Disposable schedulePeriodically​(@NonNull
                                                        @NonNull java.lang.Runnable run,
                                                        long initialDelay,
                                                        long period,
                                                        @NonNull
                                                        @NonNull java.util.concurrent.TimeUnit unit)
        Schedules a periodic execution of the given task with the given initial time delay and repeat period.

        The default implementation schedules and reschedules the Runnable task via the schedule(Runnable, long, TimeUnit) method over and over and at a fixed rate, that is, the first execution will be after the initialDelay, the second after initialDelay + period, the third after initialDelay + 2 * period, and so on.

        Note to implementors: non-positive initialTime and period should be regarded as non-delayed scheduling of the first and any subsequent executions. In addition, a more specific Worker implementation should override this method if it can perform the periodic task execution with less overhead (such as by avoiding the creation of the wrapper and tracker objects upon each periodic invocation of the common schedule(Runnable, long, TimeUnit) method).

        Parameters:
        run - the Runnable to execute periodically
        initialDelay - time to wait before executing the action for the first time; non-positive values indicate an non-delayed schedule
        period - the time interval to wait each time in between executing the action; non-positive values indicate no delay between repeated schedules
        unit - the time unit of period
        Returns:
        a Disposable to be able to unsubscribe the action (cancel it if not executed)
        Throws:
        java.lang.NullPointerException - if run or unit is null
      • now

        public long now​(@NonNull
                        @NonNull java.util.concurrent.TimeUnit unit)
        Returns the 'current time' of the Worker in the specified time unit.
        Parameters:
        unit - the time unit
        Returns:
        the 'current time'
        Throws:
        java.lang.NullPointerException - if unit is null
        Since:
        2.0