directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trustin Lee <>
Subject Re: [seda] event notifier pattern clarification
Date Wed, 22 Sep 2004 09:05:55 GMT
Alex and I talked alot on IRC and I agree with his opinion completely.

> interface Advice {
> ...
>     Subscription[] getSubscriptions(Event, Subscriptions[]);
>     Event getEvent(Event);
> }

This API has two problems:

1. Using array implies very frequent allocation of arrays which occurs
whenever EventRouter gets an advice.  So I suggest to use some
reusable object.

2. EventRouter must call two methods (getSubscriptions and getEvent)
for each event, and it can imply duplicate calculation on the same
event.  For example, let's assume that there is an advice that
transforms the specific type of event and filters its subscriptions,
then the 'if' block which identifies the type of the event is executed
twice, and it is an wate of time.

so.. I suggest this method:

public class RouterAdvice {
	// assume getters and setters exist
	Event event;
	List subscriptions;

public interface RouterAdvisor { // RouterAdvice in Alex's code
	void getAdvice(RouterAdvice);

RouterAdvisor.getAdvice() gets both event and subscriptions and then
sets back the transformed (or not transformed) event and modifies the
subscription list.

the advantage of this method is:

1. RouterAdvice is reused (using threadlocal? not sure about this), so
there is less overhead on GC.

2. Can get RouterAdvice in a single method invocation, so there is no
duplicate code.

but don't you think the name 'getAdvice' is strange?  It does not have
a return type. :)

what we call human nature in actually is human habit

View raw message