public class SimpleEventScheduler extends Object implements EventScheduler, Lifecycle
EventScheduler
implementation that 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 QuartzEventScheduler
.QuartzEventScheduler
Modifier and Type | Class and Description |
---|---|
static class |
SimpleEventScheduler.Builder
Builder class to instantiate a
SimpleEventScheduler . |
Lifecycle.LifecycleHandler, Lifecycle.LifecycleRegistry
Modifier | Constructor and Description |
---|---|
protected |
SimpleEventScheduler(SimpleEventScheduler.Builder builder)
Instantiate a
SimpleEventScheduler based on the fields contained in the SimpleEventScheduler.Builder . |
Modifier and Type | Method and Description |
---|---|
static SimpleEventScheduler.Builder |
builder()
Instantiate a Builder to be able to create a
SimpleEventScheduler . |
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 |
shutdown()
Shuts down this event scheduler.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
reschedule, reschedule
protected SimpleEventScheduler(SimpleEventScheduler.Builder builder)
SimpleEventScheduler
based on the fields contained in the SimpleEventScheduler.Builder
.
Will assert that the ScheduledExecutorService
, EventBus
and TransactionManager
are not
null
, and will throw an AxonConfigurationException
if any of them is null
.
builder
- the SimpleEventScheduler.Builder
used to instantiate a SimpleEventScheduler
instancepublic static SimpleEventScheduler.Builder builder()
SimpleEventScheduler
.
The TransactionManager
is defaulted to a NoTransactionManager
. The
ScheduledExecutorService
and EventBus
are a hard requirements and as such should be
provided.
SimpleEventScheduler
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 publishpublic 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 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.