Class SimpleDeadlineManager
- All Implemented Interfaces:
DeadlineManager
DeadlineManager which uses Java's ScheduledExecutorService as scheduling and
triggering mechanism.
Note that this mechanism is non-persistent. Scheduled tasks will be lost when the JVM is shut down, unless special
measures have been taken to prevent that. For more flexible and powerful scheduling options, see
QuartzDeadlineManager.
A fired deadline runs in a unit of work from the configured UnitOfWorkFactory, with the registered handler
interceptors around its delivery to the ScopeAware components of the
ScopeAwareProvider. A failing delivery is logged, as the deadline cannot be retried.
SimpleDeadlineManager deadlineManager =
SimpleDeadlineManager.builder()
.scopeAwareProvider(scopeAwareProvider)
.unitOfWorkFactory(configuration.getComponent(UnitOfWorkFactory.class))
.build();
- Since:
- 3.3
- Author:
- Milan Savic, Steven van Beelen, Jakob Hatzl
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class to instantiate aSimpleDeadlineManager. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aSimpleDeadlineManagerbased on the fields contained in theSimpleDeadlineManager.Builderto handle the process around scheduling and triggering aDeadlineMessage. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Instantiate a Builder to be able to create aSimpleDeadlineManager.voidCancels all the deadlines corresponding to the givendeadlineName.voidcancelAllWithinScope(String deadlineName, ScopeDescriptor scope) Cancels all deadlines corresponding to the givendeadlineNameandscope.voidcancelSchedule(String deadlineName, String scheduleId) Cancels the deadline corresponding to the givendeadlineName/scheduleIdcombination.schedule(Instant triggerDateTime, String deadlineName, @Nullable Object messageOrPayload, ScopeDescriptor deadlineScope) Schedules a deadline at giventriggerDateTimewith provided context.voidshutdown()Shuts down this deadline manager.Methods inherited from class org.axonframework.deadline.AbstractDeadlineManager
asDeadlineMessage, dispatchInterceptors, handlerInterceptors, processDispatchInterceptors, registerDispatchInterceptor, registerHandlerInterceptor, runOnPrepareCommitOrNowMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.deadline.DeadlineManager
cancelAllWithinScope, schedule, schedule, schedule, schedule, schedule
-
Constructor Details
-
SimpleDeadlineManager
Instantiate aSimpleDeadlineManagerbased on the fields contained in theSimpleDeadlineManager.Builderto handle the process around scheduling and triggering aDeadlineMessage.Will assert that the
ScopeAwareProvider,ScheduledExecutorServiceandUnitOfWorkFactoryare notnull, and will throw anAxonConfigurationExceptionif either of them isnull.- Parameters:
builder- theSimpleDeadlineManager.Builderused to instantiate aSimpleDeadlineManagerinstance
-
-
Method Details
-
builder
Instantiate a Builder to be able to create aSimpleDeadlineManager.The
ScheduledExecutorServiceis defaulted to anExecutors.newSingleThreadScheduledExecutor()which contains anAxonThreadFactory. TheScopeAwareProviderand theUnitOfWorkFactoryare hard requirements and as such should be provided.- Returns:
- a Builder to be able to create a
SimpleDeadlineManager
-
schedule
public String schedule(Instant triggerDateTime, String deadlineName, @Nullable Object messageOrPayload, ScopeDescriptor deadlineScope) Description copied from interface:DeadlineManagerSchedules a deadline at giventriggerDateTimewith provided context. The returnedscheduleIdand provideddeadlineNamecombination can be used to cancel the scheduled deadline.The given
messageOrPayloadmay be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload andMetadataof the actual deadline being used. In the former case, the givenmessageOrPayloadwill be wrapped as the payload of aDeadlineMessage.- Parameters:
triggerDateTime- aInstantdenoting the moment to trigger the deadline handlingdeadlineName- aStringrepresenting the name of the deadline to schedulemessageOrPayload- aMessageor payload for a message as anObjectdeadlineScope- aScopeDescriptordescribing the scope within which the deadline was scheduled- Returns:
- the
scheduleIdas aStringto use when cancelling the schedule
-
cancelSchedule
Description copied from interface:DeadlineManagerCancels the deadline corresponding to the givendeadlineName/scheduleIdcombination. This method has no impact on deadlines which have already been triggered. -
cancelAll
Description copied from interface:DeadlineManagerCancels all the deadlines corresponding to the givendeadlineName. This method has no impact on deadlines which have already been triggered.- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancel
-
cancelAllWithinScope
Description copied from interface:DeadlineManagerCancels all deadlines corresponding to the givendeadlineNameandscope. This method has no impact on deadlines which have already been triggered.- Parameters:
deadlineName- aStringrepresenting the name of the deadlines to cancelscope- aScopeDescriptordescribing the scope within which the deadline was scheduled
-
shutdown
public void shutdown()Shuts down this deadline manager.The configuration calls this method for every
DeadlineManagerit holds when the application shuts down, through theDeadlineManagerLifecycleConfigurationEnhancer. As the method may be called more than once, for example by Spring as the destroy method it infers for a@Bean, implementations have to allow repeated calls: every call after the first has no effect.Shuts down the
ScheduledExecutorService, which ignores every further call.
-