|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.enhydra.barracuda.core.event.DefaultEventDispatcher
This class is responsible for dispatching a queue of events to interested listeners. If you ever want to create a custom dispatching policy, this is the class to extend.
This particular implementation takes a repeating two phased dispatch approach in order to provide a Model 2 flow control mechanism. In order to pull this off, the incoming DispatchQueue must be an instance of DefaultDispatchQueue. If it is not, an EventException will be thrown.
Basically, we dispatch all the non-Response events in the queue first. Listeners which handle these events loosely correspond to controllers. Then, we dispatch all the Response events. Listeners that handle these loosely correspond to views. If a response is required and there is no response event, we look to the queue state to locate a DEFAULT_RESPONSE_EVENT, which defaults to HttpResponseEvent. To implement a single phase dispatch, just define the queue as not requiring a response and avoid adding Response events to it.
Note that when we are dispatching, if we encounter an event that implements Polymorphic, we create and dispatch parent events first. If we enouncter an event that implements Exceptional and that event is NOT handled, then we add it's parent event to the queue.
Note that the getEventChain method could probably be better optimized...
Field Summary | |
static String |
DEFAULT_RESPONSE_EVENT
|
protected static org.apache.log4j.Logger |
logger
|
static int |
MAX_DISPATCH_QUEUE_DEPTH
|
static int |
MAX_POLY_CHAIN_DEPTH
|
Constructor Summary | |
DefaultEventDispatcher()
|
Method Summary | |
protected void |
dispatch(int dispatchPhase,
EventBroker eb,
EventContext context,
DefaultDispatchQueue eventQueue)
Dispatch a queue of events |
void |
dispatchEvent(EventBroker eb,
EventContext context)
Dispatch a queue of events. |
protected List |
findListeners(BaseEvent event,
EventBroker eb)
Find the listeners for an event |
protected List |
getEventChain(BaseEvent event)
Get the event chain for a particular event. |
protected void |
notifyListeners(BaseEvent event,
List list,
EventContext context)
Actually dispatch the specific event to the list of listener factories |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String DEFAULT_RESPONSE_EVENT
public static int MAX_POLY_CHAIN_DEPTH
public static int MAX_DISPATCH_QUEUE_DEPTH
protected static final org.apache.log4j.Logger logger
Constructor Detail |
public DefaultEventDispatcher()
Method Detail |
public void dispatchEvent(EventBroker eb, EventContext context) throws EventException
Dispatch a queue of events. The incoming queue must be an instance of DefaultDispatchQueue or an EventException will be thrown. This means that if you're going to provide a custom event broker, you may need to provide a custom dispatcher as well.
Note: this is really a repeating 2 Phase approach -- we will continue to do dispatch until there are no remaining unhandled events in the queue. This allows response event handlers to add non-response events back into the queue (ie. for logging purposes, etc) and we are guaranteed that they will get dispatched (barring an exception getting thrown)
dispatchEvent
in interface EventDispatcher
eb
- the event broker to be used to match events to listenerscontext
- the event context for this whole dispatch cycle
EventException
protected void dispatch(int dispatchPhase, EventBroker eb, EventContext context, DefaultDispatchQueue eventQueue) throws EventException
dispatchPhase
- an internal flag to determine whether we're in REQ or RESP phaseeb
- the event broker to be used to match events to listenerscontext
- the event context for this whole dispatch cycleeventQueue
- the default dispatch queue
EventException
protected List getEventChain(BaseEvent event) throws EventException
event
- the base event for which we're trying to find an event chain
EventException
protected List findListeners(BaseEvent event, EventBroker eb)
event
- the base event for which we're trying to find listenerseb
- the event broker to use when looking up listenersprotected void notifyListeners(BaseEvent event, List list, EventContext context) throws EventException
event
- the event to be dispatchedlist
- the list of listeners to be notified for this particular eventcontext
- the event context containing event, queue, and, sometimes, http information
EventException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |