|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.enhydra.barracuda.core.event.DefaultEventBroker
An EventBroker is responsible for two basic tasks:
Typically, only the ApplicationGateway will actually dispatch events using the event broker.
There are two ways to register for Events. One is to specify the type of Event you're interested in. The other is simply to register a listener for general availability...anything addressed to that listener will be delivered. Note that when we're registering listeners, we're really registering listener factories. This allows the broker not to worry about syncronization issues, assuming that the factory will take care of that detail.
Note that when adding listeners, the broker calculates aliases for both listener IDs and events. This allows you to reference listeners and events by using just the class name instead of having to use the fully qualified class name. You can also add/remove aliases manually. Note however, that aliases are never automatically removed by the system, even when you remove listeners. This is because there is no way of knowing how _many_ listeners correspond with a particular alias. So...we just leave the aliases registered. In practice, this shouldn't really impact things as most listeners will only be deregistered at the end of the servlet lifecycle.
When there is more than one id for a given alias, the broker treats it as an ambiguous case and returns no match for that particular alias.
The event extension is used by whatever instantiates the broker (usually an ApplicationGateway) to define the particular event extension this broker is handling).
Field Summary | |
protected DispatcherFactory |
dispatcherFactory
|
protected java.util.Map |
eventMap
|
protected java.util.Map |
eventXref
|
protected java.lang.String |
extension
|
protected java.util.Map |
idMap
|
protected java.util.Map |
idXref
|
protected static org.apache.log4j.Logger |
logger
|
Constructor Summary | |
DefaultEventBroker(DispatcherFactory idispatcherFactory,
java.lang.String iextension)
Public constructor |
Method Summary | |
protected void |
addAliases(java.lang.String id,
java.util.List aliases,
java.util.Map xref)
Given an id and a list of aliases, add them to the specified xref |
void |
addEventAlias(java.lang.Class event)
Manually register aliases for a given event (the aliases will be determined automatically based on the class name and the event ID) |
void |
addEventAlias(java.lang.Class event,
java.lang.String alias)
Manually add an alias for a given event. |
void |
addEventListener(ListenerFactory factory)
register a listener id, so that events addressed to a specific listener can be delivered |
void |
addEventListener(ListenerFactory factory,
java.lang.Class event)
add an event listener for a particular class of an event. |
void |
dispatchEvent(EventContext context)
Dispatch a queue of events. |
protected java.util.List |
getAliases(java.lang.String className)
The purpose of this method is to take a fully qualified class name and return a list of aliases for it. |
java.lang.String |
getEventExtension()
Return the event extension handled by this event broker |
ListenerFactory |
getEventListener(java.lang.Object id)
Get a specific listener based on listener ID |
java.util.List |
getEventListeners(java.lang.Class event)
Get a List of listeners for a type of event. |
static void |
main(java.lang.String[] args)
|
java.lang.String |
matchEventClass(java.lang.String eventStr)
Given a partial event class name, return the fully qualified class name if it's possible to determine. |
java.lang.String |
matchListenerID(java.lang.String idStr)
Given a partial id name, return the fully qualified listener ID if it's possible to determine. |
void |
purgeEventListener(ListenerFactory factory)
remove all references to an event listener, both for id and for any event classes it has registered an interest in. |
void |
removeEventListener(ListenerFactory factory)
remove a listener from general availability |
void |
removeEventListener(ListenerFactory factory,
java.lang.Class event)
remove an event listener for specific types of events If the class referenced is not an instance of BaseEvent, a InvalidClassException will be thrown. |
void |
runTest()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static org.apache.log4j.Logger logger
protected java.util.Map idMap
protected java.util.Map eventMap
protected java.util.Map idXref
protected java.util.Map eventXref
protected java.lang.String extension
protected DispatcherFactory dispatcherFactory
Constructor Detail |
public DefaultEventBroker(DispatcherFactory idispatcherFactory, java.lang.String iextension)
idispatcherFactory
- a reference to the dispatcher factory
to be used in creating dispatchersiextension
- the extension to be associated with all events
delivered through the dispatcherMethod Detail |
public java.lang.String getEventExtension()
getEventExtension
in interface EventBroker
public void addEventListener(ListenerFactory factory)
addEventListener
in interface EventBroker
factory
- the listener factory to be addedpublic void addEventListener(ListenerFactory factory, java.lang.Class event) throws InvalidClassException
addEventListener
in interface EventBroker
factory
- the listener factory to be addedevent
- the specific class of event for which the factory is listening
InvalidClassException
- if the event class does not implement BaseEventpublic void removeEventListener(ListenerFactory factory)
removeEventListener
in interface EventBroker
factory
- the listener factory to be removedpublic void removeEventListener(ListenerFactory factory, java.lang.Class event) throws InvalidClassException
removeEventListener
in interface EventBroker
factory
- the listener factory to be removedevent
- the specific class of event for which the factory is listening
InvalidClassException
- if the event class does not implement BaseEventpublic void purgeEventListener(ListenerFactory factory)
purgeEventListener
in interface EventBroker
factory
- the listener factory to be removedpublic ListenerFactory getEventListener(java.lang.Object id)
getEventListener
in interface EventBroker
id
- the listener id we're looking for
public java.util.List getEventListeners(java.lang.Class event) throws InvalidClassException
getEventListeners
in interface EventBroker
event
- the event class we are looking for
InvalidClassException
- if the event class does not implement BaseEventpublic java.lang.String matchEventClass(java.lang.String eventStr) throws InvalidClassException
matchEventClass
in interface EventBroker
eventStr
- the event name alias
InvalidClassException
- if the eventStr cannot be unambiguously
matched to a class namepublic java.lang.String matchListenerID(java.lang.String idStr) throws InvalidClassException
matchListenerID
in interface EventBroker
idStr
- the id name alias
InvalidClassException
- if the idStr cannot be unambiguously
matched to a listener id nameprotected java.util.List getAliases(java.lang.String className)
public void addEventAlias(java.lang.Class event) throws InvalidClassException
addEventAlias
in interface EventBroker
event
- the specific class of event we'd like to alias
InvalidClassException
- if the event class does not implement BaseEventpublic void addEventAlias(java.lang.Class event, java.lang.String alias) throws InvalidClassException
addEventAlias
in interface EventBroker
event
- the specific class of event we'd like to aliasalias
- the alias for this event
InvalidClassException
- if the event class does not implement BaseEventprotected void addAliases(java.lang.String id, java.util.List aliases, java.util.Map xref)
public static void main(java.lang.String[] args)
public void runTest()
public void dispatchEvent(EventContext context) throws EventException
Dispatch a queue of events. Generally, the queue will only contain one event, however, if you ever need to dispatch multiple events at once, the broker can handle it. All the real dispatching work is carried out by the underlying event dispatcher.
The event queue you pass in should contain several pieces of state information:
dispatchEvent
in interface EventBroker
context
- the EventContext to be dispatched
EventException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |