org.axonframework.eventhandling.scheduling.quartz
Class QuartzEventScheduler

java.lang.Object
  extended by org.axonframework.eventhandling.scheduling.quartz.QuartzEventScheduler
All Implemented Interfaces:
EventScheduler

public class QuartzEventScheduler
extends Object
implements EventScheduler

EventScheduler implementation that delegates scheduling and triggering to a Quartz Scheduler.

Since:
0.7
Author:
Allard Buijze
See Also:
QuartzEventScheduler.DirectEventJobDataBinder, FireEventJob

Nested Class Summary
static class QuartzEventScheduler.DirectEventJobDataBinder
          Binds the EventMessage as is to JobDataMap under QuartzEventScheduler.DirectEventJobDataBinder.EVENT_KEY.
 
Constructor Summary
QuartzEventScheduler()
           
 
Method Summary
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.
protected  org.quartz.Trigger buildTrigger(org.joda.time.DateTime triggerDateTime, org.quartz.JobKey jobKey)
          Builds a Trigger which fires the Job identified by jobKey at (or around) the given triggerDateTime.
 void cancelSchedule(ScheduleToken scheduleToken)
          Cancel the publication of a scheduled event.
 void initialize()
          Initializes the QuartzEventScheduler.
 ScheduleToken schedule(org.joda.time.DateTime triggerDateTime, Object event)
          Schedule the given event for publication at the given triggerDateTime.
 ScheduleToken schedule(org.joda.time.Duration triggerDuration, Object event)
          Schedule the given event for publication after the given triggerDuration.
 void setEventBus(EventBus eventBus)
          Sets the event bus to which scheduled events need to be published.
 void setEventJobDataBinder(EventJobDataBinder jobDataBinder)
          Sets the QuartzEventScheduler.DirectEventJobDataBinder instance which reads / writes the event message to publish to the JobDataMap.
 void setGroupIdentifier(String groupIdentifier)
          Sets the group identifier to use when scheduling jobs with Quartz.
 void setScheduler(org.quartz.Scheduler scheduler)
          Sets the backing Quartz Scheduler for this timer.
 void setTransactionManager(TransactionManager transactionManager)
          Sets the transaction manager that manages a transaction around the publication of an event.
 void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
          Sets the Unit of Work Factory instance which provides the UnitOfWork that manages the publication of the scheduled event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QuartzEventScheduler

public QuartzEventScheduler()
Method Detail

schedule

public ScheduleToken schedule(org.joda.time.DateTime 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(org.joda.time.DateTime 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(org.joda.time.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

initialize

@PostConstruct
public void initialize()
                throws org.quartz.SchedulerException
Initializes the QuartzEventScheduler. Makes the configured EventBus available to the Quartz Scheduler.

Throws:
org.quartz.SchedulerException - if an error occurs preparing the Quartz Scheduler for use.

setScheduler

public void setScheduler(org.quartz.Scheduler scheduler)
Sets the backing Quartz Scheduler for this timer.

Parameters:
scheduler - the backing Quartz Scheduler for this timer

setEventBus

public void setEventBus(EventBus eventBus)
Sets the event bus to which scheduled events need to be published.

Parameters:
eventBus - the event bus to which scheduled events need to be published.

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

setTransactionManager

public void setTransactionManager(TransactionManager transactionManager)
Sets the transaction manager that manages a transaction around the publication of an event. Using this method will configure a DefaultUnitOfWorkFactory. To use an alternative Unit of Work Factory, use setUnitOfWorkFactory(org.axonframework.unitofwork.UnitOfWorkFactory) which is configured with the proper transaction manager.

Parameters:
transactionManager - the callback to invoke before and after publication of a scheduled event

setUnitOfWorkFactory

public void setUnitOfWorkFactory(UnitOfWorkFactory unitOfWorkFactory)
Sets the Unit of Work Factory instance which provides the UnitOfWork that manages the publication of the scheduled event. Defaults to a DefaultUnitOfWorkFactory without a managed transaction, unless setTransactionManager(org.axonframework.unitofwork.TransactionManager) is used. In that case, a Transactional instance of a DefaultUnitOfWorkFactory is used.

Parameters:
unitOfWorkFactory - The UnitOfWorkFactory that creates the Unit Of Work for the Event Publication

setEventJobDataBinder

public void setEventJobDataBinder(EventJobDataBinder jobDataBinder)
Sets the QuartzEventScheduler.DirectEventJobDataBinder instance which reads / writes the event message to publish to the JobDataMap. Defaults to QuartzEventScheduler.DirectEventJobDataBinder.

Parameters:
jobDataBinder - to use


Copyright © 2010-2016. All Rights Reserved.