Class QuartzEventScheduler

java.lang.Object
org.axonframework.eventhandling.scheduling.quartz.QuartzEventScheduler
All Implemented Interfaces:
EventScheduler, Lifecycle

public class QuartzEventScheduler extends Object implements EventScheduler, Lifecycle
EventScheduler implementation that delegates scheduling and triggering to a Quartz Scheduler.
Since:
0.7
Author:
Allard Buijze
See Also:
  • Constructor Details

  • Method Details

    • builder

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

      The EventJobDataBinder is defaulted to a QuartzEventScheduler.DirectEventJobDataBinder using the configured Serializer, and the TransactionManager defaults to a NoTransactionManager. Note that if the Serializer is not set, the configuration expects the EventJobDataBinder to be set.

      The Scheduler and EventBus are hard requirements and as such should be provided.

      Returns:
      a Builder to be able to create a QuartzEventScheduler
    • schedule

      public ScheduleToken schedule(Instant triggerDateTime, Object event)
      Description copied from interface: EventScheduler
      Schedule the given event for publication at the given triggerDateTime. The returned ScheduleToken can be used to cancel the planned publication.

      The given event may be any object, as well as an EventMessage. In the latter case, the instance provided is the donor for the payload and Meta Data of the actual message being dispatched. In the former case, the given event will be wrapped as the payload of an EventMessage.

      Specified by:
      schedule in interface EventScheduler
      Parameters:
      triggerDateTime - The moment to trigger publication of the event
      event - The event to publish
      Returns:
      the token to use when cancelling the schedule
    • buildJobDetail

      protected org.quartz.JobDetail buildJobDetail(EventMessage event, org.quartz.JobKey jobKey)
      Builds the JobDetail instance for Quartz, which defines the Job that needs to be executed when the trigger fires.

      The resulting JobDetail must be identified by the given jobKey and represent a Job that dispatches the given event.

      This method may be safely overridden to change behavior. Defaults to a JobDetail to fire a FireEventJob.

      Parameters:
      event - The event to be scheduled for dispatch
      jobKey - The key of the Job to schedule
      Returns:
      a JobDetail describing the Job to be executed
    • buildTrigger

      protected org.quartz.Trigger buildTrigger(Instant triggerDateTime, org.quartz.JobKey jobKey)
      Builds a Trigger which fires the Job identified by jobKey at (or around) the given triggerDateTime.
      Parameters:
      triggerDateTime - The time at which a trigger was requested
      jobKey - The key of the job to be triggered
      Returns:
      a configured Trigger for the Job with key jobKey
    • schedule

      public ScheduleToken schedule(Duration triggerDuration, Object event)
      Description copied from interface: EventScheduler
      Schedule the given event for publication after the given triggerDuration. The returned ScheduleToken can be used to cancel the planned publication.

      The given event may be any object, as well as an EventMessage. In the latter case, the instance provided is the donor for the payload and Meta Data of the actual message being dispatched. In the former case, the given event will be wrapped as the payload of an EventMessage.

      Specified by:
      schedule in interface EventScheduler
      Parameters:
      triggerDuration - The amount of time to wait before publishing the event
      event - The event to publish
      Returns:
      the token to use when cancelling the schedule
    • cancelSchedule

      public void cancelSchedule(ScheduleToken scheduleToken)
      Description copied from interface: EventScheduler
      Cancel the publication of a scheduled event. If the events has already been published, this method does nothing.
      Specified by:
      cancelSchedule in interface EventScheduler
      Parameters:
      scheduleToken - the token returned when the event was scheduled
    • setGroupIdentifier

      public void setGroupIdentifier(String groupIdentifier)
      Sets the group identifier to use when scheduling jobs with Quartz. Defaults to "AxonFramework-Events".
      Parameters:
      groupIdentifier - the group identifier to use when scheduling jobs with Quartz
    • registerLifecycleHandlers

      public void registerLifecycleHandlers(@Nonnull Lifecycle.LifecycleRegistry lifecycle)
      Description copied from interface: Lifecycle
      Registers the activities to be executed in the various phases of an application's lifecycle. This could either be at startup, shutdown, or both.
      Specified by:
      registerLifecycleHandlers in interface Lifecycle
      Parameters:
      lifecycle - the lifecycle instance to register the handlers with
      See Also:
    • shutdown

      public void shutdown()
      Description copied from interface: EventScheduler
      Shuts down this event scheduler.
      Specified by:
      shutdown in interface EventScheduler