public class SimpleEventScheduler extends Object implements EventScheduler
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
Constructor and Description |
---|
SimpleEventScheduler(ScheduledExecutorService executorService,
EventBus eventBus)
Initialize the SimpleEventScheduler using the given
executorService as trigger and execution
mechanism, and publishes events to the given eventBus . |
SimpleEventScheduler(ScheduledExecutorService executorService,
EventBus eventBus,
TransactionManager transactionManager)
Initialize the SimpleEventScheduler using the given
executorService as trigger and execution
mechanism, and publishes events to the given eventBus . |
Modifier and Type | Method and Description |
---|---|
void |
cancelSchedule(ScheduleToken scheduleToken)
Cancel the publication of a scheduled event.
|
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 . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
reschedule
public SimpleEventScheduler(ScheduledExecutorService executorService, EventBus eventBus)
executorService
as trigger and execution
mechanism, and publishes events to the given eventBus
.executorService
- The backing ScheduledExecutorServiceeventBus
- The Event Bus on which Events are to be publishedpublic SimpleEventScheduler(ScheduledExecutorService executorService, EventBus eventBus, TransactionManager transactionManager)
executorService
as trigger and execution
mechanism, and publishes events to the given eventBus
. The eventTriggerCallback
is
invoked just before and after publication of a scheduled event.executorService
- The backing ScheduledExecutorServiceeventBus
- The Event Bus on which Events are to be publishedtransactionManager
- to manage the transaction around Event publicationpublic 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 scheduledCopyright © 2010–2018. All rights reserved.