Class SchedulerService

java.lang.Object
dev.crafty.core.scheduler.SchedulerService

public class SchedulerService extends Object
Service responsible for scheduling, executing, and managing ScheduledAction instances.

This service allows actions to be scheduled for execution after a specified duration, supports cancellation, and persists scheduling state using a StorageProvider.

Since:
1.0.0
  • Constructor Details

    • SchedulerService

      public SchedulerService()
      Constructs a new SchedulerService and initializes the storage provider.
  • Method Details

    • schedule

      public void schedule(ScheduledAction action)
      Schedules a new action for execution.

      The action is stored in memory and persisted, with its next execution time calculated from the current time and its duration.

      Parameters:
      action - the ScheduledAction to schedule
    • cancel

      public void cancel(String id)
      Cancels a scheduled action by its identifier.

      Removes the action from memory and deletes its persisted state.

      Parameters:
      id - the unique identifier of the action to cancel
    • run

      public void run()
      Executes all scheduled actions whose next execution time has been reached or passed.

      After execution, updates the next execution time and persists the new state.