Interface Scheduler

All Superinterfaces:
Module
All Known Implementing Classes:
AtomicScheduler, SchedulerThread, SyncScheduler

public interface Scheduler extends Module
A scheduler. Handles the registration and execution of tasks. Scheduler can execute tasks on a regular basis. Scheduler are categorized by two criteria: whether it is synchronous, and whether it is strict.

Synchronous schedulers only have one thread, (usually the scheduler itself) and thus can only execute tasks sequentially. On the other hand, asynchronous schedulers are capable of multithreaded operation.

Strict schedulers have no delay between each iteration, adhering to the interval of the tasks in a strict manner. Non-strict or lazy schedulers sleep after each iteration, which can help to avoid unnecessary iterations of looping through the list of tasks pointlessly. (since a task will only be executed after the interval of the task has passed)

Which implementation is used should vary between applications, selecting the appropriate implementation depending on the application's nature.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    register(Task task)
    Registers a task to this scheduler, instructing it to start executing it as soon as possible.
    void
    registerAsync(Iterable<? extends Task> tasks)
    Registers multiple tasks asynchronously to this scheduler, instructing it to distribute the tasks across multiple threads however it sees fit.
    void
    registerSync(Iterable<? extends Task> tasks)
    Registers multiple tasks synchronously to this scheduler, instructing it to put every provided task into a single thread to ensure sequential execution.
    void
    Unregisters a task from this scheduler, instructing it to stop executing it.
    void
    unregister(Iterable<? extends Task> tasks)
    Unregisters multiple tasks from this scheduler, instructing it to stop executing every task within the provided iterable object of tasks.

    Methods inherited from interface civitas.celestis.util.Module

    initialize, interrupt, start, terminate
  • Method Details

    • register

      void register(@Nonnull Task task)
      Registers a task to this scheduler, instructing it to start executing it as soon as possible.
      Parameters:
      task - The task to register to this scheduler
    • registerSync

      void registerSync(@Nonnull Iterable<? extends Task> tasks)
      Registers multiple tasks synchronously to this scheduler, instructing it to put every provided task into a single thread to ensure sequential execution.
      Parameters:
      tasks - The iterable object containing the tasks to register
    • registerAsync

      void registerAsync(@Nonnull Iterable<? extends Task> tasks)
      Registers multiple tasks asynchronously to this scheduler, instructing it to distribute the tasks across multiple threads however it sees fit. Sequential execution is not guaranteed, and this is equivalent to iteratively calling register(Task) for each task.
      Parameters:
      tasks - The iterable object containing the tasks to register
    • unregister

      void unregister(@Nonnull Task task)
      Unregisters a task from this scheduler, instructing it to stop executing it.
      Parameters:
      task - The task to unregister from this scheduler
    • unregister

      void unregister(@Nonnull Iterable<? extends Task> tasks)
      Unregisters multiple tasks from this scheduler, instructing it to stop executing every task within the provided iterable object of tasks.
      Parameters:
      tasks - The iterable object containing the tasks to unregister