Interface MessageScheduler
- All Superinterfaces:
Namespaced<MessageScheduler>
- All Known Implementing Classes:
DefaultMessageScheduler
Interface for scheduling deferred or periodic execution of messages in the Fluxzero Runtime.
The MessageScheduler provides functionality for:
- Deferring arbitrary payloads (to be handled via
HandleSchedule). - Scheduling commands (to be handled via standard
@HandleCommandhandlers). - Recurring execution using cron expressions via the
Periodicannotation.
Scheduling semantics
When using schedule(...):
- Scheduled payloads are delivered to handler methods annotated with
@HandleSchedule. - Used when the intention is to invoke scheduling-specific logic or workflows.
When using scheduleCommand(...):
- The scheduled payload will be dispatched as a command at the configured deadline.
- Handlers annotated with
@HandleCommandwill receive the message, just like normal commands. - This is useful for scenarios where both immediate and delayed invocation use the same handler logic.
Schedule identity
All schedules are identified by a scheduleId. It is recommended to always pass a scheduleId. However,
if one is not given, it is obtained from the toString() value of the Schedule payload.
If a schedule with the same ID already exists:
- It is replaced by default.
- Use
ifAbsent = trueto ensure the schedule is only created if it does not already exist.
Typical usage
This interface underpins the static helpers inFluxzero, such as:
Fluxzero.schedule(myPayload, Duration.ofMinutes(5));
Fluxzero.scheduleCommand(myCommand, Instant.now().plusSeconds(10));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidcancelSchedule(@NonNull Object scheduleId) Cancel a previously scheduled message or command by ID.getSchedule(@NonNull Object scheduleId) Look up an existing schedule.default voidSchedule a message object (typically of typeSchedule) for execution, using theGuarantee.SENTguarantee.default voidSchedule a message, optionally skipping if already present, using theGuarantee.SENTguarantee.Schedule the givenScheduleobject, optionally skipping if already present, using the specified guarantee.default voidSchedule a message with payload and metadata using a delay, using theGuarantee.SENTguarantee.default voidSchedule a message with payload and metadata, using theGuarantee.SENTguarantee.default voidSchedule a message with a custom ID using a delay.default voidSchedule a message with the given ID and deadline, using theGuarantee.SENTguarantee.default StringSchedule a message using a delay from the current time, using theGuarantee.SENTguarantee.default StringSchedule a message to be triggered at the given deadline, using theGuarantee.SENTguarantee.default voidscheduleCommand(@NonNull Schedule message) Schedule a command message using the given scheduling settings, using theGuarantee.SENTguarantee.default voidscheduleCommand(@NonNull Schedule message, boolean ifAbsent) Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENTguarantee.scheduleCommand(Schedule message, boolean ifAbsent, Guarantee guarantee) Schedule a command using the given scheduling settings, using the providedGuarantee.default voidscheduleCommand(@NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Duration delay) Schedule a command with metadata and delay, using theGuarantee.SENTguarantee.default voidscheduleCommand(@NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Instant deadline) Schedule a command message with attached metadata, using theGuarantee.SENTguarantee.default voidscheduleCommand(@NonNull Object schedule, Object scheduleId, Duration delay) Schedule a command with the given ID and delay, using theGuarantee.SENTguarantee.default voidscheduleCommand(@NonNull Object schedule, Object scheduleId, Instant deadline) Schedule a command using a specific deadline, using theGuarantee.SENTguarantee.default StringscheduleCommand(@NonNull Object schedule, Duration delay) Schedule a command to execute after given delay, using theGuarantee.SENTguarantee.default StringscheduleCommand(@NonNull Object schedule, Instant deadline) Schedule a command message for future execution.default StringschedulePeriodic(@NonNull Object value, Object scheduleId) Schedule a periodic message using the given ID and the@Periodicannotation, using theGuarantee.SENTguarantee.default StringschedulePeriodic(Object value) Schedule a periodic message using the@Periodicannotation on its class, using theGuarantee.SENTguarantee.Methods inherited from interface Namespaced
forDefaultNamespace, forNamespace
-
Method Details
-
schedulePeriodic
Schedule a periodic message using the@Periodicannotation on its class, using theGuarantee.SENTguarantee.- Parameters:
value- the payload to schedule periodically- Returns:
- the schedule ID
- Throws:
IllegalArgumentException- if the annotation is missing or misconfigured
-
schedulePeriodic
Schedule a periodic message using the given ID and the@Periodicannotation, using theGuarantee.SENTguarantee.- Parameters:
value- the payload to schedule periodicallyscheduleId- a custom ID or null to use value#toString- Returns:
- the effective schedule ID
-
schedule
Schedule a message to be triggered at the given deadline, using theGuarantee.SENTguarantee.The schedule ID will be determined by calling schedule#toString.
- Parameters:
schedule- the message to scheduledeadline- the absolute time to trigger the message- Returns:
- the schedule ID
-
schedule
Schedule a message using a delay from the current time, using theGuarantee.SENTguarantee.The schedule ID will be determined by calling schedule#toString.
- Parameters:
schedule- the message to scheduledelay- delay duration until the schedule triggers- Returns:
- the schedule ID
-
schedule
-
schedule
default void schedule(@NonNull @NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Instant deadline) Schedule a message with payload and metadata, using theGuarantee.SENTguarantee.- Parameters:
schedulePayload- the message payloadmetadata- metadata to attachscheduleId- the unique schedule IDdeadline- the deadline for triggering the schedule
-
schedule
default void schedule(@NonNull @NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Duration delay) Schedule a message with payload and metadata using a delay, using theGuarantee.SENTguarantee.- Parameters:
schedulePayload- the message payloadmetadata- metadata to attachscheduleId- the schedule IDdelay- delay from now until triggering
-
schedule
Schedule a message with the given ID and deadline, using theGuarantee.SENTguarantee.- Parameters:
schedule- the object to schedulescheduleId- unique schedule IDdeadline- the absolute time at which the schedule should trigger
-
schedule
Schedule a message object (typically of typeSchedule) for execution, using theGuarantee.SENTguarantee.- Parameters:
message- the message to schedule
-
schedule
Schedule a message, optionally skipping if already present, using theGuarantee.SENTguarantee.- Parameters:
message- the schedule messageifAbsent- whether to skip scheduling if an existing schedule is present
-
schedule
Schedule the givenScheduleobject, optionally skipping if already present, using the specified guarantee.- Parameters:
message- the schedule messageifAbsent- only schedule if not already scheduledguarantee- the delivery guarantee to use- Returns:
- a CompletableFuture completing when the message is successfully scheduled
-
scheduleCommand
Schedule a command message for future execution. This is similar toschedule(Object, Instant)but ensures the message is dispatched as a command, using theGuarantee.SENTguarantee.The schedule ID will be determined by calling schedule#toString.
- Parameters:
schedule- the command to scheduledeadline- the deadline for execution- Returns:
- the schedule ID
-
scheduleCommand
Schedule a command to execute after given delay, using theGuarantee.SENTguarantee.- Parameters:
schedule- the command to scheduledelay- delay until execution- Returns:
- the schedule ID
-
scheduleCommand
Schedule a command with the given ID and delay, using theGuarantee.SENTguarantee.- Parameters:
schedule- the command to schedulescheduleId- schedule IDdelay- delay until execution
-
scheduleCommand
default void scheduleCommand(@NonNull @NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Instant deadline) Schedule a command message with attached metadata, using theGuarantee.SENTguarantee.- Parameters:
schedulePayload- payload of the commandmetadata- metadata to attachscheduleId- schedule IDdeadline- execution deadline
-
scheduleCommand
default void scheduleCommand(@NonNull @NonNull Object schedulePayload, Metadata metadata, Object scheduleId, Duration delay) Schedule a command with metadata and delay, using theGuarantee.SENTguarantee.- Parameters:
schedulePayload- payload to schedulemetadata- metadata to attachscheduleId- schedule IDdelay- delay duration
-
scheduleCommand
default void scheduleCommand(@NonNull @NonNull Object schedule, Object scheduleId, Instant deadline) Schedule a command using a specific deadline, using theGuarantee.SENTguarantee.- Parameters:
schedule- the command object or messagescheduleId- the schedule IDdeadline- deadline for triggering the schedule
-
scheduleCommand
Schedule a command message using the given scheduling settings, using theGuarantee.SENTguarantee.- Parameters:
message- the command message
-
scheduleCommand
Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENTguarantee.- Parameters:
message- the command scheduleifAbsent- whether to skip if already scheduled
-
scheduleCommand
Schedule a command using the given scheduling settings, using the providedGuarantee.- Parameters:
message- the command scheduleifAbsent- skip if existing schedule is presentguarantee- the delivery guarantee to apply- Returns:
- a future indicating when the command is scheduled
-
cancelSchedule
Cancel a previously scheduled message or command by ID.- Parameters:
scheduleId- the ID of the schedule to cancel
-
getSchedule
-