org.axonframework.eventhandling.scheduling.java
Class SimpleEventScheduler

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

public class SimpleEventScheduler
extends Object
implements EventScheduler

An 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.

Since:
0.7
Author:
Allard Buijze
See Also:
QuartzEventScheduler

Constructor Summary
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, UnitOfWorkFactory unitOfWorkFactory)
          Initialize the SimpleEventScheduler using the given executorService as trigger and execution mechanism, and publishes events to the given eventBus.
 
Method Summary
 void cancelSchedule(ScheduleToken scheduleToken)
          Cancel the publication of a scheduled event.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleEventScheduler

public SimpleEventScheduler(ScheduledExecutorService executorService,
                            EventBus eventBus)
Initialize the SimpleEventScheduler using the given executorService as trigger and execution mechanism, and publishes events to the given eventBus.

Parameters:
executorService - The backing ScheduledExecutorService
eventBus - The Event Bus on which Events are to be published

SimpleEventScheduler

public SimpleEventScheduler(ScheduledExecutorService executorService,
                            EventBus eventBus,
                            UnitOfWorkFactory unitOfWorkFactory)
Initialize the SimpleEventScheduler using the given 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.

Parameters:
executorService - The backing ScheduledExecutorService
eventBus - The Event Bus on which Events are to be published
unitOfWorkFactory - The factory that creates the Unit of Work to manage transactions
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

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


Copyright © 2010-2016. All Rights Reserved.