commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne" <scolebou...@btopenworld.com>
Subject Re: [lang] Notifier
Date Tue, 12 Nov 2002 21:51:53 GMT
Some comments/suggestions:

- Does JDK1.4 not have something similar? Does that matter?

- There should not be a no args constructor

- The constructor/methods should validate for null passed in and throw IAE

- The setListenerMethod should be changed to be a second constructor
Notifier(Class, String)

- The getListeners method could return an unmodifiable list of listeners.
Alternatively, it should pass the listeners collection into the constructor
of ArrayList, its more efficient like that.

- The notify(Method, EventObject) method seems to expose the detail that you
are trying to hide

- The methods could/should be cached in a HashMap for the notify(String,
EventObject) case

- Synchronization is needed

- Should it have its own package - events ?

Well just some initial thoughts. Its a new area for [lang], but the event
classes are in java lang/util. If we are releasing in the next couple of
weeks it would need a little thought.

Stephen

----- Original Message -----
From: "Henri Yandell" <bayard@generationjava.com>
To: "Jakarta Commons Developers List" <commons-dev@jakarta.apache.org>
Sent: Tuesday, November 12, 2002 3:07 AM
Subject: [lang] Notifier


> I added Notifier class into Lang. I mentioned it a while back and thought
> I'd place it in to share. I still need to write a threading test around it
> to figure out exactly which methods need synchronising.
>
> Basically it makes an event-listener queue a lot easier to handle:
>
>     private Notifier notifier = new Notifier(MyListener.class);
>
>     public void addMyListener(MyListener l) {
>       notifier.addListener(l);
>     }
>
>     public void removeMyListener(MyListener l) {
>       notifier.removeListener(l);
>     }
>
>     public void foo() {
>        ...
>        notifier.notify();
>        ...
>     }
>
>
> This version automatically figures out that MyListener has only 1 method
> [for example]. If this is not the case, then the name of the method can be
> set with setListenerMethod, or the name of the method may be passed in to
> the notify method, allowing a Listener with multiple events to be handled.
>
> Events must extend java.util.EventObject.
>
> Opinions?
>
> Hen
>
>
> --
> To unsubscribe, e-mail:
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:commons-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message