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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcancelLocalDelivery(String scheduleId) voidcancelSchedule(@NonNull Object scheduleId) Cancel a previously scheduled message or command by ID.protected MessageSchedulercreateForNamespace(String namespace) protected DeserializingMessagedeserializingMessage(Schedule schedule) getSchedule(@NonNull Object scheduleId) Look up an existing schedule.voidhandleLocally(Schedule schedule) protected voidregisterHandler(Object target) Registers the given handler object and includes only the methods that are annotated with a recognized handler annotation (e.g.,@HandleCommand,@HandleQuery, etc.).registerHandler(Object target, HandlerFilter handlerFilter) Registers a handler object, including only those methods that match the providedHandlerFilter.protected RegistrationregisterLocalHandler(Supplier<Registration> registration) protected voidrunIfExpired(DefaultMessageScheduler.LocalScheduleTask task, Schedule schedule) protected booleansameSchedule(Schedule left, Schedule right) protected booleansameScheduledMessage(Schedule left, Schedule right) Schedule the givenScheduleobject, optionally skipping if already present, using the specified guarantee.scheduleCommand(Schedule schedule, boolean ifAbsent, Guarantee guarantee) Schedule a command using the given scheduling settings, using the providedGuarantee.protected voidscheduleLocalDelivery(Schedule schedule, boolean ifAbsent, Fluxzero fluxzero) protected booleanshouldScheduleLocalDelivery(Schedule schedule) Methods inherited from class AbstractNamespaced
close, forNamespaceMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasLocalHandlers
hasLocalHandlers, setSelfHandlerFilterMethods inherited from interface MessageScheduler
schedule, schedule, schedule, schedule, schedule, schedule, schedule, schedule, scheduleCommand, scheduleCommand, scheduleCommand, scheduleCommand, scheduleCommand, scheduleCommand, scheduleCommand, scheduleCommand, schedulePeriodic, schedulePeriodicMethods inherited from interface Namespaced
forDefaultNamespace, forNamespace
-
Constructor Details
-
DefaultMessageScheduler
public DefaultMessageScheduler()
-
-
Method Details
-
createForNamespace
- Specified by:
createForNamespacein classAbstractNamespaced<MessageScheduler>
-
schedule
Description copied from interface:MessageSchedulerSchedule the givenScheduleobject, optionally skipping if already present, using the specified guarantee.- Specified by:
schedulein interfaceMessageScheduler- 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
public CompletableFuture<Void> scheduleCommand(Schedule schedule, boolean ifAbsent, Guarantee guarantee) Description copied from interface:MessageSchedulerSchedule a command using the given scheduling settings, using the providedGuarantee.- Specified by:
scheduleCommandin interfaceMessageScheduler- Parameters:
schedule- the command scheduleifAbsent- skip if existing schedule is presentguarantee- the delivery guarantee to apply- Returns:
- a future indicating when the command is scheduled
-
cancelSchedule
Description copied from interface:MessageSchedulerCancel a previously scheduled message or command by ID.- Specified by:
cancelSchedulein interfaceMessageScheduler- Parameters:
scheduleId- the ID of the schedule to cancel
-
getSchedule
Description copied from interface:MessageSchedulerLook up an existing schedule.- Specified by:
getSchedulein interfaceMessageScheduler- Parameters:
scheduleId- the ID of the schedule- Returns:
- the schedule if found
-
handleLocally
-
registerHandler
Description copied from interface:HasLocalHandlersRegisters 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
LocalHandlerto determine which methods to include. If a payload has an annotated handler likeHandleQueryinside its class and the class is not annotated withTrackSelf, the handler is also considered to be local.- Specified by:
registerHandlerin interfaceHasLocalHandlers- Parameters:
target- the object containing handler methods- Returns:
- a
Registrationwhich can be used to unregister the handlers
-
registerHandler
Description copied from interface:HasLocalHandlersRegisters a handler object, including only those methods that match the providedHandlerFilter.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:
registerHandlerin interfaceHasLocalHandlers- Parameters:
target- the handler object containing annotated methodshandlerFilter- the filter used to determine which methods should be registered- Returns:
- a
Registrationwhich can be used to unregister the handlers
-
scheduleLocalDelivery
-
runIfExpired
-
registerLocalHandler
-
shouldScheduleLocalDelivery
-
cancelLocalDelivery
-
handleLocalSchedule
-
deserializingMessage
-
sameSchedule
-
sameScheduledMessage
-