RE: Barracuda: Automatic creation of ListenerFactories?

"Christian Cryder" <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi Ron,

> For instance, instead of having a lot of lines like this in my gateways:
>
> private ListenerFactory doUpdateAccountFactory = new
> DefaultListenerFactory()
> {public BaseEventListener getInstance() {return new
> DoUpdateAccountHandler();}    public String getListenerID() {return
> getID(DoUpdateAccountHandler.class);}};

Ok, if you are using inner class event handlers, there simply is no way
around this (that I've been able to think of...and I spent quite a bit of
time trying too); the problem is that only the containing class has the
authority to instantiate the inner class, so there must be a "hook" placed
in the code to provide that instance, and that's what the above code does.

What I like to do is run the whole thing onto one line; even though it
extends off the right hand side of the page, its basically a declaration and
it makes the whole thing a bit more readable (IMO).

The only alternative (if you don't like this) is to go away from using inner
class event handlers. You can certainly do this if you want (I don't care
for it, personally, because it spreads things out into a lot more classes;
some people like it though). If you are willing to go with regular classes
for you handlers, then you actually can do this:

> I would love to put something like this into my descriptor instead:
>
> <event-interest handler="DoUpdateAccountHandler"
> factoryClass="DefaultListenerFactory"
> event="com.eb5.website.events.DoUpdateAccount" />

If you look in DefaultApplicationAssembler, ca. line 440, you will see the
code where it tries to do this. Basically, it looks to see if factory name
matches a property (variable) in the current gateway, and if not, it tries
to instantiate it on the fly. Once it has a handle to the factory, it will
also invoke specifyLocalEventInterests() on it as well. You can find an
example in the event-gateway.xml file that comes with Barracuda: look for
"Junior!" and you'll see it.

Now, the one final issue (and I think this is what Jake was referencing) is
that if you are listening for a parent event who's child events are not
explicitly registered anywhere else in the system, you also have to manually
do a specifyLocalEventAliases() for those events, so that Barracuda knows
how to map from the first class event object to all the possible URL event
aliases. I would like to eliminate the need to do this...my basic idea at
this point is somehow figuring out a way at compile time to generate a map
of all known events in the system...we could then feed this to the
EventBroker so that it would be able to create the appropriate mappings for
them. This would eliminate the need to call specifyLocalEventAliases(); it
would NOT remove the need to declare a factory method and call
specifyLocalEventInterests() if you are using inner classes.

Does that answer your question?

Christian
----------------------------------------------
Christian Cryder [[email protected]]
Internet Architect, ATMReports.com
Barracuda - http://barracuda.enhydra.org
----------------------------------------------
"Coffee? I could quit anytime, just not today"


> -----Original Message-----
> From: [email protected] [mailto:[email protected]]On
> Behalf Of Ron Alsobrook
> Sent: Wednesday, December 04, 2002 3:43 PM
> To: [email protected]
> Subject: Barracuda: Automatic creation of ListenerFactories?
>
>
> This may have come up before, but has anyone given any thought to
> having the
> ApplicationAssembler automatically create ListenerFactories based on the
> assembly descriptor file?
>
> For instance, instead of having a lot of lines like this in my gateways:
>
> private ListenerFactory doUpdateAccountFactory = new
> DefaultListenerFactory()
> {public BaseEventListener getInstance() {return new
> DoUpdateAccountHandler();}    public String getListenerID() {return
> getID(DoUpdateAccountHandler.class);}};
>
> I would love to put something like this into my descriptor instead:
>
> <event-interest handler="DoUpdateAccountHandler"
> factoryClass="DefaultListenerFactory"
> event="com.eb5.website.events.DoUpdateAccount" />
>
> ...and have the ApplicationAssembler create the factories for me.
>  Or maybe
> the factory should be seperate to better support multiple
> listeners/events
> like this:
>
> <factory name="doUpdateAccountFactory" handler="DoUpdateAccountHandler"
> factoryClass="DefaultListenerFactory" />
>
> Then the <event-interest>s would stay as they are now:
>
> <event-interest factory="doUpdateAccountFactory"
> event="com.eb5.website.events.DoUpdateAccount" />
>
> One thing to note, my handler classes are usually inner classes
> of the gateway
> and I don't know how that would affect things.  Thoughts anyone?
>
> Ron
>
> _______________________________________________
> Barracuda mailing list
> [email protected]
> http://www.enhydra.org/mailman/listinfo.cgi/barracuda
> FAQ - http://www.jguru.com/faq/Barracuda

_______________________________________________
Barracuda mailing list
[email protected]
http://www.enhydra.org/mailman/listinfo.cgi/barracuda
FAQ - http://www.jguru.com/faq/Barracuda
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.