org.enhydra.barracuda.core.event
Class DefaultDispatchQueue

java.lang.Object
  extended byorg.enhydra.barracuda.core.event.DefaultDispatchQueue
All Implemented Interfaces:
DispatchQueue

public class DefaultDispatchQueue
extends Object
implements DispatchQueue

The DispatchQueue as a relatively shortlived structure...the Queue would be created by the dispatcher, and it would be discarded when the events have been delivered. It should be made available to the listeners, however, so that they can add events to the queue if they'd like.

While the DispatchQueue interface views the queue as one list of events, the DefaultDispatchQueue is designed to be aware of two different kinds of events: Control events, and View events. This corresponds nicely with both the Http Req/Response model and the Model 2 Controller/View distinction.

This means that when you add an event to the queue, internally gets filtered into either a control list or a view list. Consequently, when iterating through the queue, you will always get all control events first, then you will get all view events. The DefaultEventDispatcher makes use of this distinction to implement a 2 phase event dispatch: request events are dispatched first, followed by response events.

The queue can also be used for a single phased dispatch by setting requiresResponse = false.

The queue is smart enough so that as you add events to it, duplicate events are collapsed together and redundancies are eliminated (ie. if I add 3 RepaintView events, they would be combined into one, which appears at the end of the queue).

As a final note, observe that not all of the methods are public. This is to limit BaseEventListener access: listeners add events to the queue, see what events are in the queue, and even mark them handled. But they cannot actually remove events from the queue. That duty belongs to the Event Dispatcher, which of necessity must be in the same package as the DispatchQueue in order to be able to access all methods.


Field Summary
protected  List controlList
           
protected static org.apache.log4j.Logger logger
           
protected  List procList
           
protected  boolean requiresResponse
           
protected  boolean responseHandled
           
protected  List viewList
           
 
Constructor Summary
DefaultDispatchQueue(boolean irequiresResponse)
          Public noargs constructor.
 
Method Summary
 void addEvent(BaseEvent baseEvent)
          Adds an event to the queue.
 void dumpEventQueueToConsole(int targetDepth)
          Dunp event queue to console for debugging purposes.
 List listProcessedEvents()
          List events which have already been processed through the queue
 List listRemainingEvents()
          List all events remaining in the queue (Request events first, then Response events)
 int numberOfEventsProcessed()
          get the number of events that have been processed
 int numberOfEventsRemaining()
          get the number of events remaining in the queue
 boolean requiresResponse()
          Does this queue require a response?
 boolean responseHandled()
          Has the response for this queue been handled?
 void setRequiresResponse(boolean val)
          Programatically tell the dispatcher that a response is required
 void setResponseHandled(boolean val)
          Mark the response as handled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

requiresResponse

protected boolean requiresResponse

responseHandled

protected boolean responseHandled

controlList

protected List controlList

viewList

protected List viewList

procList

protected List procList
Constructor Detail

DefaultDispatchQueue

public DefaultDispatchQueue(boolean irequiresResponse)
Public noargs constructor. A queue must be defined as requiring a response or not. This value can not be changed during the life of the queue. Typically, any queue created to service an HTTP request will set this value to true.

Parameters:
irequiresResponse - true if this queue requires a response
Method Detail

requiresResponse

public boolean requiresResponse()
Does this queue require a response?

Specified by:
requiresResponse in interface DispatchQueue
Returns:
true if this queue requires a response

setRequiresResponse

public void setRequiresResponse(boolean val)
Programatically tell the dispatcher that a response is required

Specified by:
setRequiresResponse in interface DispatchQueue

responseHandled

public boolean responseHandled()
Has the response for this queue been handled?

Specified by:
responseHandled in interface DispatchQueue
Returns:
true if the response has been handled

setResponseHandled

public void setResponseHandled(boolean val)
Mark the response as handled

Specified by:
setResponseHandled in interface DispatchQueue
Parameters:
val - whether or not the response has been handled

addEvent

public void addEvent(BaseEvent baseEvent)
Adds an event to the queue. When this happens, we first remove any existing events in the queue that this event .equals(), and then this event is added. This has the effect of collapsing duplicates.

Specified by:
addEvent in interface DispatchQueue
Parameters:
baseEvent - the event to be added to the queue

numberOfEventsRemaining

public int numberOfEventsRemaining()
get the number of events remaining in the queue

Specified by:
numberOfEventsRemaining in interface DispatchQueue
Returns:
the number of events remaining in the queue

listRemainingEvents

public List listRemainingEvents()
List all events remaining in the queue (Request events first, then Response events)

Specified by:
listRemainingEvents in interface DispatchQueue
Returns:
a list of all events remaining in the queue

numberOfEventsProcessed

public int numberOfEventsProcessed()
get the number of events that have been processed

Specified by:
numberOfEventsProcessed in interface DispatchQueue
Returns:
the number of events processed in the queue

listProcessedEvents

public List listProcessedEvents()
List events which have already been processed through the queue

Specified by:
listProcessedEvents in interface DispatchQueue
Returns:
a list of all events processed in the queue

dumpEventQueueToConsole

public void dumpEventQueueToConsole(int targetDepth)
Dunp event queue to console for debugging purposes.

Parameters:
targetDepth - the depth at which we should start printing debug information


Copyright © 2003 BarracudaMVC.org All Rights Reserved.