public interface EventService extends EventProducer
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 calls
transactionCommitted()
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 marked Event.isCommitEvent()
is used to flush
the event bundle to its listeners, otherwise the transaction commit does the
flush.
Listeners are of two types: EventListener
notified as the event is
raised and PostCommitEventListener
notified after the transaction was
committed.
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(EventListenerDescriptor listener)
Adds a new event listener.
|
void |
addTransactionListener(EventTransactionListener listener)
Adds an event transaction listener.
|
void |
fireEvent(Event event)
Fires an event.
|
void |
fireEvent(String name,
EventContext context)
Fires an event given its name and a context.
|
void |
fireEventBundle(EventBundle event)
Fires all recorded events in a transaction.
|
void |
fireEventBundleSync(EventBundle event)
Fires an event bundle in synchronous mode.
|
List<EventListener> |
getEventListeners()
Gets the list of the registered event listeners.
|
List<PostCommitEventListener> |
getPostCommitEventListeners()
Get the list of the registered post commit event listeners.
|
boolean |
isTransactionStarted()
Tests whether or not a transaction was started.
|
void |
removeEventListener(EventListenerDescriptor listener)
Removes an event listener.
|
void |
removeTransactionListener(EventTransactionListener listener)
Removes the given event transaction listener.
|
void |
transactionCommitted()
Notifies that the transaction was committed.
|
void |
transactionRolledback()
Notifies that transaction was rolled back.
|
void |
transactionStarted()
Notifies that a transaction was started.
|
void |
waitForAsyncCompletion()
Waits until all asynchronous tasks are finished.
|
void |
waitForAsyncCompletion(long timeout)
Waits until all asynchronous tasks are finished, but waits no longer than
the given number of milliseconds.
|
void addEventListener(EventListenerDescriptor listener)
The event listener is described by a EventListenerDescriptor
that
may specify a priority. Both types of listeners (immediate and
post-commit) are registered.
listener
- the listener to addvoid removeEventListener(EventListenerDescriptor listener)
listener
- the listener to removevoid fireEvent(String name, EventContext context) throws ClientException
name
- the event namecontext
- the event contextClientException
void fireEvent(Event event) throws ClientException
If a transaction was started, the event is registered if needed to be sent after the transaction commit.
fireEvent
in interface EventProducer
event
- the event to fireClientException
void fireEventBundle(EventBundle event) throws ClientException
The events are fired to PostCommitEventListener
listeners. Events
are fired in the form of an event bundle.
fireEventBundle
in interface EventProducer
event
- the event bundleClientException
void fireEventBundleSync(EventBundle event) throws ClientException
This means that asynchronous listeners will be run synchronously.
ClientException
List<EventListener> getEventListeners()
Modification on this list will not modify the internal lists in this
EventService
.
List<PostCommitEventListener> getPostCommitEventListeners()
Modification on this list will not modify the internal lists in this
EventService
.
void transactionStarted()
Any fired events will be recorded until the transaction is terminated
either by calling transactionRolledback()
either
transactionCommitted()
.
void transactionCommitted() throws ClientException
This will fire the events collected during the transaction in the form of
a EventBundle
. After this the recording will stop and recorded
events discarded.
ClientException
void transactionRolledback()
This will discard any recorded event.
boolean isTransactionStarted()
void waitForAsyncCompletion()
void waitForAsyncCompletion(long timeout)
timeout
- the maximum time to wait for, in millisecondsvoid addTransactionListener(EventTransactionListener listener)
void removeTransactionListener(EventTransactionListener listener)
Copyright © 2011 Nuxeo SA. All Rights Reserved.