|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object i3.dragos.core.AbstractService i3.dragos.core.services.events.EventManager
public class EventManager
The EventManager is responsible for distributing events to the registered event listeners. It is transacation-aware and implements event queueing, so listeners can precisely specify when in the life cycle of a transaction they want to receive their events.
A note about the order of event firing, especially for those implementing multiple types of listeners at once:
The EventManager also serves a secondary purpose: Because he is informed about every change in the graph data anyway, he marks transactions as "dirty", which means that consistency is not guaranteed until a consistency check is performed (which will also reset the "dirty" flag).
A remark about the "generic event" facility: Please note that this is not the only way for an extension to use custom events! In fact, if your event can be expressed as a subclass of any of the pre-defined event classes, it is strongly encouraged to do so, especially for DataEvents, where you gain transaction-awareness for free!
For much more information about EventManager and associated classes, please refer to the "Guide to Events and Rules" in the documentation.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface i3.dragos.core.Service |
---|
Service.Result, Service.State |
Constructor Summary | |
---|---|
EventManager()
Creates an EventManager instance. |
Method Summary | ||
---|---|---|
void |
addDataListener(DataListener l,
EventCouplingMode mode,
DataSourceURL ds)
Registers a DataListener. |
|
|
addGenericListener(java.lang.Class<T> channelInterface,
T listener)
Adds a generic listener. |
|
void |
addGraphPoolListener(GraphPoolListener l)
Registers a GraphPoolListener. |
|
void |
addPreFilter(EventFilter f)
Adds an EventFilter that is consulted for every event before it is processed. |
|
void |
addTransactionListener(TransactionListener l,
TransactionManager tm)
Registers a TransactionListener. |
|
void |
fireDataEvent(DataEvent e)
Fires an event after a GraphEntity changes. |
|
|
fireGenericEvent(java.lang.Class<T> channelInterface,
java.util.EventObject event,
java.lang.reflect.Method method)
Fires a generic event. |
|
void |
fireGraphPoolEvent(GraphPoolEvent e)
Fires a GraphPoolEvent. |
|
void |
fireTransactionEvent(TransactionEvent e)
Fires a TransactionEvent. |
|
static EventManager |
getInstance()
Returns the event manager instance registered by the service manager. |
|
java.lang.String |
getName()
Returns the name of the service. |
|
java.util.List<EventFilter> |
getPreFilters()
Returns all currently registered pre-filters. |
|
void |
removeDataListener(DataListener l,
EventCouplingMode mode,
DataSourceURL ds)
Unregisters a DataListener. |
|
|
removeGenericListener(java.lang.Class<T> channelInterface,
T listener)
Removes a generic listener. |
|
void |
removeGraphPoolListener(GraphPoolListener l)
Unregisters a GraphPoolListener. |
|
void |
removePreFilter(EventFilter f)
Removes a pre-filter. |
|
void |
removeTransactionListener(TransactionListener l,
TransactionManager tm)
Unregisters a TransactionListener. |
Methods inherited from class i3.dragos.core.AbstractService |
---|
getState, initialize, resume, start, stop, suspend, uninitialize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EventManager()
Method Detail |
---|
public static EventManager getInstance()
public java.lang.String getName()
public void addPreFilter(EventFilter f)
The EventFilter.accepts(i3.dragos.core.services.events.DragosEvent)
method is called on all EventFilters in
the same order they were added, until one of them does not accept the
event. Only if all pre-filters accept the event, it will be processed as
usual by the EventManager.
The main application for this method is for extensions to supress events generated by manipulation of their meta-data. These events should not become visible to the application and might confuse it. You may even employ this method to rewrite events, by firing you own modified event and rejecting the original one.
Pre-filters can not be used for the generic event distribution service offered by EventManager, only for DragosEvent's.
When using pre-filters to suppress transaction events, you should be
aware that this also affects the transaction-awareness of the
EventManager itself (DataEvent queues for
EventCouplingMode.BEFORE_COMMIT
and
EventCouplingMode.AFTER_COMMIT
), because pre-filters are applied
before any event evaluation!
f
- The EventFilter (must not be null
).public void removePreFilter(EventFilter f)
f
- The EventFilter (must not be null
).addPreFilter(EventFilter)
public java.util.List<EventFilter> getPreFilters()
addPreFilter(EventFilter)
public void addDataListener(DataListener l, EventCouplingMode mode, DataSourceURL ds)
null
indicates that the listener wants to be
informed about all transactions.
A DataListener can register multiple times, which means that he will
receive each event more than once. A separate list of listeners is
maintained for each category, where category means a specific
EventCouplingMode/DataSourceURL pair (where the DataSourceURL may be
null
). When unregistering, you have to specify the same
parameter values you used when registering, otherwise EventManager will
look in the wrong category and not find the correct listener entry (or
none at all).
l
- The DataListener (must not be null
).mode
- The EventCouplingMode (must not be null
).ds
- The DataSourceURL (may be null
).public void removeDataListener(DataListener l, EventCouplingMode mode, DataSourceURL ds)
l
- The DataListener (must not be null
).mode
- The EventCouplingMode (must not be null
).ds
- The DataSourceURL (may be null
).addDataListener(DataListener, EventCouplingMode, DataSourceURL)
public void fireDataEvent(DataEvent e) throws DragosException
e
- The DataEvent.
DragosException
- in case of internal or nested errors.public void addTransactionListener(TransactionListener l, TransactionManager tm)
null
indicates that the listener wants to
be informed about all transactions.
A TransactionListener can register multiple times, which means that he
will receive each event more than once. A separate list of listeners is
maintained for each category, where category means a specific
TransactionManager or the special case null
. When
unregistering, you have to specify the same tm
value you
used when registering, otherwise EventManager will look in the wrong
category and not find the correct listener entry (or none at all).
l
- The TransactionListener (must not be null
).tm
- The TransactionManager (may be null
).public void removeTransactionListener(TransactionListener l, TransactionManager tm)
l
- The TransactionListener (must not be null
).tm
- The TransactionManager (may be null
).addTransactionListener(TransactionListener, TransactionManager)
public void fireTransactionEvent(TransactionEvent e) throws DragosException
e
- The TransactionEvent.
DragosException
- in case of any errors.public void addGraphPoolListener(GraphPoolListener l)
A GraphPoolListener can register multiple times, which means that he will receive each event more than once.
l
- The GraphPoolListener (must not be null
).public void removeGraphPoolListener(GraphPoolListener l)
If it has been registered multiple times, only one of these registrations is removed.
l
- The GraphPoolListener (must not be null
).addGraphPoolListener(GraphPoolListener)
public void fireGraphPoolEvent(GraphPoolEvent e) throws DragosException
e
- The GraphPoolEvent.
DragosException
- in case of any errors.public <T extends java.util.EventListener> void addGenericListener(java.lang.Class<T> channelInterface, T listener)
T
- the listener interface for the channel.channelInterface
- The EventListener interface that identifies this channel and
also must be implemented by all listeners on that channel.listener
- The listener to add.public <T extends java.util.EventListener> void removeGenericListener(java.lang.Class<T> channelInterface, T listener)
T
- the listener interface for the channel.channelInterface
- The EventListener interface that identifies this channel and
also must be implemented by all listeners on that channel.listener
- The listener to remove.public <T extends java.util.EventListener> void fireGenericEvent(java.lang.Class<T> channelInterface, java.util.EventObject event, java.lang.reflect.Method method) throws java.lang.IllegalArgumentException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
T
- the listener interface for the channel.channelInterface
- The EventListener interface that identifies this channel and
also must be implemented by all listeners on that channel.event
- The event to fire.method
- The method to invoke on the listeners (must exist at all
listeners (should be defined in the channel interface anyway)
and must accept the event type as the only parameter!).
java.lang.reflect.InvocationTargetException
- see
Method.invoke(java.lang.Object, java.lang.Object[])
for details.
java.lang.IllegalAccessException
- see
Method.invoke(java.lang.Object, java.lang.Object[])
for details.
java.lang.IllegalArgumentException
- see
Method.invoke(java.lang.Object, java.lang.Object[])
for details.Method.invoke(java.lang.Object, java.lang.Object[])
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |