Class SimpleDeadlineManager

java.lang.Object
org.axonframework.deadline.AbstractDeadlineManager
org.axonframework.deadline.SimpleDeadlineManager
All Implemented Interfaces:
DeadlineManager

public class SimpleDeadlineManager extends AbstractDeadlineManager
Implementation of 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
  • Constructor Details

  • Method Details

    • builder

      public static SimpleDeadlineManager.Builder builder()
      Instantiate a Builder to be able to create a SimpleDeadlineManager.

      The ScheduledExecutorService is defaulted to an Executors.newSingleThreadScheduledExecutor() which contains an AxonThreadFactory. The ScopeAwareProvider and the UnitOfWorkFactory are 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: DeadlineManager
      Schedules a deadline at given triggerDateTime with provided context. The returned scheduleId and provided deadlineName combination can be used to cancel the scheduled deadline.

      The given messageOrPayload may be any object, as well as a DeadlineMessage. In the latter case, the instance provided is the donor for the payload and Metadata of the actual deadline being used. In the former case, the given messageOrPayload will be wrapped as the payload of a DeadlineMessage.

      Parameters:
      triggerDateTime - a Instant denoting the moment to trigger the deadline handling
      deadlineName - a String representing the name of the deadline to schedule
      messageOrPayload - a Message or payload for a message as an Object
      deadlineScope - a ScopeDescriptor describing the scope within which the deadline was scheduled
      Returns:
      the scheduleId as a String to use when cancelling the schedule
    • cancelSchedule

      public void cancelSchedule(String deadlineName, String scheduleId)
      Description copied from interface: DeadlineManager
      Cancels the deadline corresponding to the given deadlineName / scheduleId combination. This method has no impact on deadlines which have already been triggered.
      Parameters:
      deadlineName - a String representing the name of the deadline to cancel
      scheduleId - the String denoting the scheduled deadline to cancel
    • cancelAll

      public void cancelAll(String deadlineName)
      Description copied from interface: DeadlineManager
      Cancels all the deadlines corresponding to the given deadlineName. This method has no impact on deadlines which have already been triggered.
      Parameters:
      deadlineName - a String representing the name of the deadlines to cancel
    • cancelAllWithinScope

      public void cancelAllWithinScope(String deadlineName, ScopeDescriptor scope)
      Description copied from interface: DeadlineManager
      Cancels all deadlines corresponding to the given deadlineName and scope. This method has no impact on deadlines which have already been triggered.
      Parameters:
      deadlineName - a String representing the name of the deadlines to cancel
      scope - a ScopeDescriptor describing the scope within which the deadline was scheduled
    • shutdown

      public void shutdown()
      Shuts down this deadline manager.

      The configuration calls this method for every DeadlineManager it holds when the application shuts down, through the DeadlineManagerLifecycleConfigurationEnhancer. 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.