Annotation Interface HandleSchedule
@Documented
@Retention(RUNTIME)
@Target({METHOD,CONSTRUCTOR})
@HandleMessage(SCHEDULE)
public @interface HandleSchedule
Marks a method or constructor as a handler for scheduled messages (
MessageType.SCHEDULE).
These handlers are invoked in response to scheduled triggers, typically time-based.
Scheduled messages may originate from an explicit schedule call (see
MessageScheduler), or from a payload annotated with Periodic, which
enables automatic rescheduling after each invocation.
Return behavior
A@HandleSchedule method may return a value to control rescheduling behavior:
null: continue scheduling using the default strategy if the schedule isPeriodic.DurationorInstant: overrides the next schedule delay or time.- A new payload: schedules the returned object as the next scheduled message. If this new payload is annotated
with
Periodic, the periodic settings on that payload take precedence. - Returning a new
Schedulereschedules that message using the specified payload and deadline.
To cancel a periodic schedule, throw a CancelPeriodic exception.
Example: Dynamic continuation using payload return
@HandleSchedule
PollUpdates on(PollUpdates poll) {
var updates = Fluxzero.queryAndWait(poll);
// Process updates
return new PollUpdates(updates.getContinuationToken());
}
If PollUpdates is annotated with Periodic, its delay or cron expression will be used for rescheduling.
Example: Return a delay for the next schedule
@HandleSchedule
Duration on(HealthCheck ping) {
if (!isAlive()) {
throw new CancelPeriodic("Service offline");
}
return Duration.ofSeconds(30);
}
This will schedule the same ping message to be retried after 30 seconds.- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]Restricts which payload types this handler may be invoked for.booleanIftrue, disables this handler during discovery.
-
Element Details
-
disabled
boolean disabledIftrue, disables this handler during discovery.- Default:
false
-
allowedClasses
Class<?>[] allowedClassesRestricts which payload types this handler may be invoked for.- Default:
{}
-