|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.utils.listener.Listeners<Listener>
public class Listeners<Listener extends java.util.EventListener>
This object is implementing listeners list, where you may store both type of references to
the listeners (strong reference / weak reference).
It takes quite of effort to maintain the list with both strong / weak references,
therefore the class was created.
Because we don't know what method we will be calling on the listeners the public
interface ListenerNotifier exists. If you want to fire all the listeners, just
implement this interface and stuff it to the notify() method of the "Listeners".
(This somehow resembles the Stored Procedure pattern...)
Another interface is used for removing listeners. You may want to go through the listeners
list and mark some of them to be removed (according to some rule like 'instanceof'). See
static interface ListenerRemover.
The class is thread-safe.
Nested Class Summary | |
---|---|
static class |
Listeners.AdaptableListenerNotifier<LISTENER extends IListener>
|
static interface |
Listeners.ListenerNotifier<Listener extends java.util.EventListener>
Used to raise the event in the listeners. |
static interface |
Listeners.ListenerRemover
Used as a visitor to the listeners that should tell which listeners to remove... |
Constructor Summary | |
---|---|
Listeners()
|
Method Summary | |
---|---|
void |
addStrongListener(Listener listener)
Adds listener with strong reference to it. |
void |
addWeakListener(Listener listener)
Adds listener with weak reference to it. |
void |
clearListeners()
|
int |
count()
Returns count of listners in the list, note that this may not be exact as we store also listeners with weak listeners, but the list will be purged in next opportunity (like raising event, removing listener). |
boolean |
isEqualListening(java.util.EventListener listener)
Returns true if at least one equals listener to the param 'listener' is found. |
boolean |
isListening(java.util.EventListener listener)
Returns true if at least one == listener to the param 'listener' is found. |
void |
notify(Listeners.ListenerNotifier<Listener> notifier)
Calls notifier.notify() on each of the stored listeners, allowing you to execute stored command. |
boolean |
notifySafe(Listeners.ListenerNotifier<Listener> notifier,
java.util.logging.Logger exceptionLog)
Calls notifier.notify() on each of the stored listeners, allowing you to execute stored command. |
void |
remove(Listeners.ListenerRemover remover)
This will iterate over all of the listeners and do the query "whether the listner should be removed from the Listeners object". |
int |
removeEqualListener(java.util.EventListener listener)
Removes all listeners that are equal() to this one. |
int |
removeListener(java.util.EventListener listener)
Removes all listeners that are == to this one (not equal()! must be the same object). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Listeners()
Method Detail |
---|
public void addStrongListener(Listener listener)
listener
- public void addWeakListener(Listener listener)
listener
- public int removeEqualListener(java.util.EventListener listener)
listener
-
public int removeListener(java.util.EventListener listener)
listener
-
public void notify(Listeners.ListenerNotifier<Listener> notifier)
notifier
- public boolean notifySafe(Listeners.ListenerNotifier<Listener> notifier, java.util.logging.Logger exceptionLog)
Every notification is run inside try/catch block, exceptions are reported into the log (if not null) and method returns false if some exception is thrown.
notifier
- exceptionLog
- where to log exceptions, may be null
public boolean isEqualListening(java.util.EventListener listener)
listener
-
public boolean isListening(java.util.EventListener listener)
listener
-
public void clearListeners()
public int count()
public void remove(Listeners.ListenerRemover remover)
remover
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |