Class JobRunrDeadlineManager

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

public class JobRunrDeadlineManager extends AbstractDeadlineManager
Implementation of DeadlineManager that delegates scheduling and triggering to a JobRunr JobScheduler.

Each deadline is stored as a JobRunr job calling execute(String, String) on this manager, with the deadline's DeadlineDetails in their stored form as the first argument. The details keep the layout of Axon Framework 4.13, so that jobs scheduled by Axon Framework 4 fire here, and jobs scheduled here fire on Axon Framework 4 nodes sharing JobRunr's storage. The details and the deadline's payload, metadata and scope descriptor are converted with the configured Converter, which has to match the serializer the Axon Framework 4 deadline manager used.

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 fails the job, which JobRunr then retries.

cancelAll(String) and cancelAllWithinScope(String, ScopeDescriptor) are not supported, as they need JobRunr Pro. Keep the identifier schedule(Instant, String, Object, ScopeDescriptor) returns to cancel a deadline with cancelSchedule(String, String) instead.


 JobRunrDeadlineManager deadlineManager =
         JobRunrDeadlineManager.builder()
                               .jobScheduler(jobScheduler)
                               .scopeAwareProvider(scopeAwareProvider)
                               .unitOfWorkFactory(configuration.getComponent(UnitOfWorkFactory.class))
                               .converter(new JacksonConverter())
                               .build();
 
Since:
4.7.0
Author:
Tom de Backer, Gerard Klijs, Jakob Hatzl
  • Field Details

  • Constructor Details

  • Method Details

    • builder

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

      The JobScheduler, ScopeAwareProvider, UnitOfWorkFactory and Converter are hard requirements and as such should be provided.

      Returns:
      a Builder to be able to create a JobRunrDeadlineManager
    • 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)
      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
      Throws:
      UnsupportedOperationException - always, as cancelling by deadline name needs JobRunr Pro
    • cancelAllWithinScope

      public void cancelAllWithinScope(String deadlineName, ScopeDescriptor scope)
      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
      Throws:
      UnsupportedOperationException - always, as cancelling by Scope needs JobRunr Pro
    • execute

      @Deprecated(since="4.8.0") public void execute(String serializedDeadlineDetails)
      Deprecated.
      Kept so that jobs scheduled through this signature still fire. New jobs call execute(String, String).
      This method is called by JobRunr for jobs scheduled by Axon Framework 4 before it passed the deadline identifier. It fires the deadline as execute(String, String) does.
      Parameters:
      serializedDeadlineDetails - the stored DeadlineDetails of the deadline to fire
    • execute

      public void execute(String serializedDeadlineDetails, @Nullable String deadlineId)
      This method is called by JobRunr when a deadline fires. It converts the stored DeadlineDetails back into the deadline, and delivers it to the components resolving its scope.

      The signature stays exactly as in Axon Framework 4, as JobRunr stores the call to this method with every job.

      Parameters:
      serializedDeadlineDetails - the stored DeadlineDetails of the deadline to fire
      deadlineId - the identifier of the deadline, which JobRunr uses as the job's identifier
      Throws:
      DeadlineException - if delivering the deadline failed, so that JobRunr retries the job
    • 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 JobScheduler once. As that shuts down JobRunr as a whole, every further call has no effect.