Annotation 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 is Periodic.
  • Duration or Instant: 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 Schedule reschedules 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 = FluxCapacitor.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 Elements
    Modifier and Type
    Optional Element
    Description
    Class<?>[]
    Restricts which payload types this handler may be invoked for.
    boolean
    If true, disables this handler during discovery.
  • Element Details

    • disabled

      boolean disabled
      If true, disables this handler during discovery.
      Default:
      false
    • allowedClasses

      Class<?>[] allowedClasses
      Restricts which payload types this handler may be invoked for.
      Default:
      {}