Module aeonics.core

Class Scheduler

  • All Implemented Interfaces:
    Exportable, Snapshotable

    public abstract class Scheduler
    extends Manager.Type
    Manages execution of scheduled tasks. The scheduler will inspect the Registry for all Scheduler.Cron and will run them accordingly.

    It is not expected that the scheduler have a precision smaller than 1 second.

    • Constructor Detail

      • Scheduler

        public Scheduler()
    • Method Detail

      • manager

        public final java.lang.Class<? extends Manager.Type> manager()
        Hardcoded manager type
        Specified by:
        manager in class Manager.Type
        Returns:
        the type of manager
      • at

        public abstract void at​(java.util.function.Consumer<java.time.ZonedDateTime> task,
                                java.time.ZonedDateTime time)
        Schedules a task to run once at the specified time. If the time is past due, the task runs immediately.
        Parameters:
        task - the task to run, it will receive the current time when called
        time - the time at which the task should run
      • in

        public void in​(java.util.function.Consumer<java.time.ZonedDateTime> task,
                       long delay)
        Schedules a task to run once after the specified delay has elapsed.
        Parameters:
        task - the task to run, it will receive the current time when called
        delay - the number of milliseconds of delay from the time of calling this method
      • every

        public Scheduler.Cron.Type every​(java.util.function.Consumer<java.time.ZonedDateTime> task,
                                         long step,
                                         java.time.temporal.ChronoUnit unit)
        Schedules a task to run at a specified time interval.
        Parameters:
        task - the task to run, it will receive the current time when called
        step - the time interval
        unit - the time unit
        Returns:
        the cron task
      • every

        public Scheduler.Cron.Type every​(java.util.function.Consumer<java.time.ZonedDateTime> task,
                                         long step,
                                         java.time.temporal.ChronoUnit unit,
                                         java.time.ZonedDateTime from)
        Schedules a task to run at a specified time interval starting a the specified moment.
        Parameters:
        task - the task to run, it will receive the current time when called
        step - the time interval
        unit - the time unit
        from - the starting point in time
        Returns:
        the cron task
      • refresh

        public abstract void refresh()
        This method will re-inspect all Scheduler.Cron in the Registry to determine if some tasks need to run. You should call this method every time a Cron task is added in the Registry so that the scheduler recomputes the next action date.