Interface Task

All Known Implementing Classes:
DelayedTask

public interface Task
Defines the contract of a task which can be registered and executed by a scheduler. Tasks are provided with a delta each execution, which is the amount of time between the last execution and now in milliseconds.

All methods excluding execute(long) are default, making this interface declarable by use of a lambda expression. This is an intended feature, and this will continue to be the only abstract method in the future.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The default interval of a task in milliseconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    execute(long delta)
    Executes this task.
    default long
    Returns the interval of this task.
    default void
    Called upon registration to a scheduler.
    default void
    Called upon unregistration from a scheduler.
  • Field Details

    • DEFAULT_INTERVAL

      static final long DEFAULT_INTERVAL
      The default interval of a task in milliseconds.
      See Also:
  • Method Details

    • execute

      void execute(long delta)
      Executes this task.
      Parameters:
      delta - The duration between the last execution and now in milliseconds
    • interval

      default long interval()
      Returns the interval of this task.
      Returns:
      The interval of this task in milliseconds
    • onRegistered

      default void onRegistered(@Nonnull Scheduler scheduler)
      Called upon registration to a scheduler.
      Parameters:
      scheduler - The scheduler this task was registered to
    • onUnregistered

      default void onUnregistered(@Nonnull Scheduler scheduler)
      Called upon unregistration from a scheduler.
      Parameters:
      scheduler - The scheduler this task was unregistered from