public class QuartzEventScheduler extends Object implements EventScheduler, Lifecycle
EventJobDataBinder
,
FireEventJob
Modifier and Type | Class and Description |
---|---|
static class |
QuartzEventScheduler.Builder
Builder class to instantiate a
QuartzEventScheduler . |
static class |
QuartzEventScheduler.DirectEventJobDataBinder
|
Lifecycle.LifecycleHandler, Lifecycle.LifecycleRegistry
Modifier | Constructor and Description |
---|---|
protected |
QuartzEventScheduler(QuartzEventScheduler.Builder builder)
Instantiate a
QuartzEventScheduler based on the fields contained in the QuartzEventScheduler.Builder . |
Modifier and Type | Method and Description |
---|---|
static QuartzEventScheduler.Builder |
builder()
Instantiate a Builder to be able to create a
QuartzEventScheduler . |
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(Instant 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 |
registerLifecycleHandlers(Lifecycle.LifecycleRegistry lifecycle)
Registers the activities to be executed in the various phases of an application's lifecycle.
|
ScheduleToken |
schedule(Duration triggerDuration,
Object event)
Schedule the given
event for publication after the given triggerDuration . |
ScheduleToken |
schedule(Instant triggerDateTime,
Object event)
Schedule the given
event for publication at the given triggerDateTime . |
void |
setGroupIdentifier(String groupIdentifier)
Sets the group identifier to use when scheduling jobs with Quartz.
|
void |
shutdown()
Shuts down this event scheduler.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
reschedule, reschedule
protected QuartzEventScheduler(QuartzEventScheduler.Builder builder)
QuartzEventScheduler
based on the fields contained in the QuartzEventScheduler.Builder
.
Will assert that the Scheduler
and EventBus
are not null
,
and will throw an AxonConfigurationException
if any of them is null
.
The EventBus, TransactionManager and EventJobDataBinder will be tied to the Scheduler's context. If this
initialization step fails, this will too result in an AxonConfigurationException.
builder
- the QuartzEventScheduler.Builder
used to instantiate a QuartzEventScheduler
instancepublic static QuartzEventScheduler.Builder builder()
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.
QuartzEventScheduler
public ScheduleToken schedule(Instant triggerDateTime, Object event)
EventScheduler
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.schedule
in interface EventScheduler
triggerDateTime
- The moment to trigger publication of the eventevent
- The event to publishprotected org.quartz.JobDetail buildJobDetail(EventMessage event, org.quartz.JobKey jobKey)
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
.event
- The event to be scheduled for dispatchjobKey
- The key of the Job to scheduleprotected org.quartz.Trigger buildTrigger(Instant triggerDateTime, org.quartz.JobKey jobKey)
jobKey
at (or around) the given
triggerDateTime
.triggerDateTime
- The time at which a trigger was requestedjobKey
- The key of the job to be triggeredjobKey
public ScheduleToken schedule(Duration triggerDuration, Object event)
EventScheduler
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.schedule
in interface EventScheduler
triggerDuration
- The amount of time to wait before publishing the eventevent
- The event to publishpublic void cancelSchedule(ScheduleToken scheduleToken)
EventScheduler
cancelSchedule
in interface EventScheduler
scheduleToken
- the token returned when the event was scheduledpublic void setGroupIdentifier(String groupIdentifier)
groupIdentifier
- the group identifier to use when scheduling jobs with Quartzpublic void registerLifecycleHandlers(@Nonnull Lifecycle.LifecycleRegistry lifecycle)
Lifecycle
registerLifecycleHandlers
in interface Lifecycle
lifecycle
- the lifecycle instance to register the handlers withLifecycle.LifecycleRegistry.onShutdown(int, Runnable)
,
LifecycleRegistry#onShutdown(int, LifecycleHandler)
,
Lifecycle.LifecycleRegistry.onStart(int, Runnable)
,
LifecycleRegistry#onStart(int, LifecycleHandler)
public void shutdown()
EventScheduler
shutdown
in interface EventScheduler
Copyright © 2010–2024. All rights reserved.