Package dev.crafty.core.scheduler
Class SchedulerService
java.lang.Object
dev.crafty.core.scheduler.SchedulerService
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 Summary
ConstructorsConstructorDescriptionConstructs a newSchedulerService
and initializes the storage provider. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Cancels a scheduled action by its identifier.void
run()
Executes all scheduled actions whose next execution time has been reached or passed.void
schedule
(ScheduledAction action) Schedules a new action for execution.
-
Constructor Details
-
SchedulerService
public SchedulerService()Constructs a newSchedulerService
and initializes the storage provider.
-
-
Method Details
-
schedule
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
- theScheduledAction
to schedule
-
cancel
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.
-