Class DefaultMessageScheduler

java.lang.Object
io.fluxzero.sdk.common.AbstractNamespaced<MessageScheduler>
io.fluxzero.sdk.scheduling.DefaultMessageScheduler
All Implemented Interfaces:
Namespaced<MessageScheduler>, MessageScheduler, HasLocalHandlers

public class DefaultMessageScheduler extends AbstractNamespaced<MessageScheduler> implements MessageScheduler, HasLocalHandlers
Default implementation of the MessageScheduler interface.

This implementation uses a SchedulingClient to schedule and cancel scheduled messages. When a schedule has a matching local handler, a TaskScheduler task wakes up at the deadline and invokes the local handler in-process.

  • Constructor Details

    • DefaultMessageScheduler

      public DefaultMessageScheduler()
  • Method Details

    • createForNamespace

      protected MessageScheduler createForNamespace(String namespace)
      Specified by:
      createForNamespace in class AbstractNamespaced<MessageScheduler>
    • schedule

      public CompletableFuture<Void> schedule(Schedule message, boolean ifAbsent, Guarantee guarantee)
      Description copied from interface: MessageScheduler
      Schedule the given Schedule object, optionally skipping if already present, using the specified guarantee.
      Specified by:
      schedule in interface MessageScheduler
      Parameters:
      message - the schedule message
      ifAbsent - only schedule if not already scheduled
      guarantee - the delivery guarantee to use
      Returns:
      a CompletableFuture completing when the message is successfully scheduled
    • scheduleCommand

      public CompletableFuture<Void> scheduleCommand(Schedule schedule, boolean ifAbsent, Guarantee guarantee)
      Description copied from interface: MessageScheduler
      Schedule a command using the given scheduling settings, using the provided Guarantee.
      Specified by:
      scheduleCommand in interface MessageScheduler
      Parameters:
      schedule - the command schedule
      ifAbsent - skip if existing schedule is present
      guarantee - the delivery guarantee to apply
      Returns:
      a future indicating when the command is scheduled
    • cancelSchedule

      public void cancelSchedule(@NonNull @NonNull Object scheduleId)
      Description copied from interface: MessageScheduler
      Cancel a previously scheduled message or command by ID.
      Specified by:
      cancelSchedule in interface MessageScheduler
      Parameters:
      scheduleId - the ID of the schedule to cancel
    • getSchedule

      public Optional<Schedule> getSchedule(@NonNull @NonNull Object scheduleId)
      Description copied from interface: MessageScheduler
      Look up an existing schedule.
      Specified by:
      getSchedule in interface MessageScheduler
      Parameters:
      scheduleId - the ID of the schedule
      Returns:
      the schedule if found
    • handleLocally

      public void handleLocally(Schedule schedule)
    • registerHandler

      public Registration registerHandler(Object target)
      Description copied from interface: HasLocalHandlers
      Registers the given handler object and includes only the methods that are annotated with a recognized handler annotation (e.g., @HandleCommand, @HandleQuery, etc.).

      This method uses LocalHandler to determine which methods to include. If a payload has an annotated handler like HandleQuery inside its class and the class is not annotated with TrackSelf, the handler is also considered to be local.

      Specified by:
      registerHandler in interface HasLocalHandlers
      Parameters:
      target - the object containing handler methods
      Returns:
      a Registration which can be used to unregister the handlers
    • registerHandler

      public Registration registerHandler(Object target, HandlerFilter handlerFilter)
      Description copied from interface: HasLocalHandlers
      Registers a handler object, including only those methods that match the provided HandlerFilter.

      This method offers fine-grained control over which handler methods are registered, based on custom logic applied to method annotations and/or signatures.

      Specified by:
      registerHandler in interface HasLocalHandlers
      Parameters:
      target - the handler object containing annotated methods
      handlerFilter - the filter used to determine which methods should be registered
      Returns:
      a Registration which can be used to unregister the handlers
    • scheduleLocalDelivery

      protected void scheduleLocalDelivery(Schedule schedule, boolean ifAbsent, Fluxzero fluxzero)
    • runIfExpired

      protected void runIfExpired(DefaultMessageScheduler.LocalScheduleTask task, Schedule schedule)
    • registerLocalHandler

      protected Registration registerLocalHandler(Supplier<Registration> registration)
    • shouldScheduleLocalDelivery

      protected boolean shouldScheduleLocalDelivery(Schedule schedule)
    • cancelLocalDelivery

      protected void cancelLocalDelivery(String scheduleId)
    • handleLocalSchedule

      protected void handleLocalSchedule(DefaultMessageScheduler.LocalScheduleTask task)
    • deserializingMessage

      protected DeserializingMessage deserializingMessage(Schedule schedule)
    • sameSchedule

      protected boolean sameSchedule(Schedule left, Schedule right)
    • sameScheduledMessage

      protected boolean sameScheduledMessage(Schedule left, Schedule right)