Interface EventService
- 
- All Superinterfaces:
- EventProducer
 - All Known Implementing Classes:
- EventServiceImpl
 
 public interface EventService extends EventProducer The event service manages listener registries and notifies listeners about core events.The service is able to run in a transactional mode where all events are recorded and fired after the transaction commits in one step as an event bundle. To start a transaction, the framework calls the transactionStarted()method, and at transaction commit the framework callstransactionCommitted()to fire the event bundle. Upon rollback the framework callstransactionRolledback()to clean up recorded events.Events are recorded in a thread variable so they are valid only in the current thread. An event marked Event.isInline()is dispatched immediately, otherwise it is recorded in a thread-based bundle of current events. If no transaction was started, an event markedEvent.isCommitEvent()is used to flush the event bundle to its listeners, otherwise the transaction commit does the flush.Listeners are of two types: EventListenernotified as the event is raised andPostCommitEventListenernotified after the transaction was committed.
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddEventListener(EventListenerDescriptor listener)Adds a new event listener.List<DomainEventProducer>createDomainEventProducers()Creates the registered domain event producers.voidfireEvent(String name, EventContext context)Fires an event given its name and a context.voidfireEvent(Event event)Fires an event.voidfireEventBundle(EventBundle event)Fires all recorded events in a transaction.voidfireEventBundleSync(EventBundle event)Fires an event bundle in synchronous mode.EventListenerDescriptorgetEventListener(String name)Gets the event listener descriptor corresponding to the give name.List<EventListener>getEventListeners()Gets the list of the registered event listeners.List<PostCommitEventListener>getPostCommitEventListeners()Get the list of the registered post commit event listeners.voidremoveEventListener(EventListenerDescriptor listener)Removes an event listener.voidwaitForAsyncCompletion()Waits until all asynchronous tasks are finished.voidwaitForAsyncCompletion(long timeout)Waits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.
 
- 
- 
- 
Method Detail- 
addEventListenervoid addEventListener(EventListenerDescriptor listener) Adds a new event listener. Used by the framework.The event listener is described by a EventListenerDescriptorthat may specify a priority. Both types of listeners (immediate and post-commit) are registered.- Parameters:
- listener- the listener to add
 
 - 
removeEventListenervoid removeEventListener(EventListenerDescriptor listener) Removes an event listener. Used by the framework.- Parameters:
- listener- the listener to remove
 
 - 
fireEventvoid fireEvent(String name, EventContext context) Fires an event given its name and a context.- Parameters:
- name- the event name
- context- the event context
 
 - 
fireEventvoid fireEvent(Event event) Fires an event.If a transaction was started, the event is registered if needed to be sent after the transaction commit. - Specified by:
- fireEventin interface- EventProducer
- Parameters:
- event- the event to fire
 
 - 
fireEventBundlevoid fireEventBundle(EventBundle event) Fires all recorded events in a transaction. Used by the framework.The events are fired to PostCommitEventListenerlisteners. Events are fired in the form of an event bundle.- Specified by:
- fireEventBundlein interface- EventProducer
- Parameters:
- event- the event bundle
 
 - 
fireEventBundleSyncvoid fireEventBundleSync(EventBundle event) Fires an event bundle in synchronous mode. Used by the framework.This means that asynchronous listeners will be run synchronously. 
 - 
getEventListenersList<EventListener> getEventListeners() Gets the list of the registered event listeners.Modification on this list will not modify the internal lists in this EventService.- Returns:
- the event listeners
 
 - 
getPostCommitEventListenersList<PostCommitEventListener> getPostCommitEventListeners() Get the list of the registered post commit event listeners.Modification on this list will not modify the internal lists in this EventService.- Returns:
- the post commit event listeners
 
 - 
getEventListenerEventListenerDescriptor getEventListener(String name) Gets the event listener descriptor corresponding to the give name.- Parameters:
- name- the event listener name
- Returns:
- the descriptor, or nullif not found
- Since:
- 5.8
 
 - 
waitForAsyncCompletionvoid waitForAsyncCompletion() Waits until all asynchronous tasks are finished.
 - 
waitForAsyncCompletionvoid waitForAsyncCompletion(long timeout) Waits until all asynchronous tasks are finished, but waits no longer than the given number of milliseconds.- Parameters:
- timeout- the maximum time to wait for, in milliseconds
 
 - 
createDomainEventProducersList<DomainEventProducer> createDomainEventProducers() Creates the registered domain event producers.- Since:
- 11.4
 
 
- 
 
-