Event Flow?
Kirk Daries <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <D09B591872D1D611AF2B0010B5A1AAD0527EBD@WCSMAIL> |
Hi...
I've a small event design/flow question.
Consider the following:
I use a few common parameters across my entire application and I'd like to
create a single validation listener for these params.
The listeners should validate and populate a data structure for
use in later events.
E.g.
The user submits the following url:
http://localhost:8080/myApp/SomeEvent.event?p_param1=bla&p_param2=blabla&p_p
aram3=AntoherBla
I have the following design at the moment:
SomeEvent_Listener --> SomeEvent.event
validateQueryParams_Listener --> validateQueryParams.event
SomeEvent.event extends validateQueryParams.event.
The validateQueryParams_Listener looks for specific params in the url.
If if finds them.... it should then go and call their induvidual validators.
Upon successful validation and population...
proceed and process the target Event (SomeEvent.event).
Here's some code from the validateQueryParams_Listener
E.g.
String param1;
String param2;
BaseEvent newEvent;
//Read parms fromt request..
....bla code here
if ((param1 == null) && (param2 == null)) {
newEvent = new DefaultValidationEvent();
} else if ((param1 != null) && (param2 == null)) {
newEvent = new ValidateAndPopulateXYZ();
} else if ((param1 != null) && (param2 != null)) {
newEvent = new ValidateAndPopulateBlaBla();
}
if (newEvent != null) {
newEvent.setSource(event);
DispatchQueue queue = context.getQueue();
queue.addEvent(newEvent);
}
HOWEVER!
My design is flawed..
When the user sumits the url.
The validateQueryParams_Listener does fire.. and adds the correct
validationEvent to the event queue;
However...
SomeEvent.event is firing before the validationEvents because it appears
in the queue before the validation events.
E.g.
Currently... this is the order of events firing...
validateQueryParams.event --> SomeEvent.event -->
ValidationAndPopulateEvent.event
I'd like to have:
validateQueryParams.event --> ValidationAndPopulateEvent.event -->
SomeEvent.event
The problem is 'queue.addEvent'.
Maybe there needs to be a mechanism to add a event to the queue to be
processed imediatly
before processing the queue normally? Maybe priorities?
In the mean time..
I had thought of extending interuptedDispatchException.... passing in the
targetEvent as a param..
and then adding the targetEvent back into the queue.
But I don't particularly like this approach.
Is there a easier way?
Am I missing something?
Any one got any ideas?
Regards
KD