commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject [lang] Notifier
Date Tue, 12 Nov 2002 03:07:40 GMT
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>


Mime
View raw message