public class Listeners<Listener extends EventListener> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Listeners.AdaptableListenerNotifier<LISTENER extends IListener> |
static interface |
Listeners.ListenerNotifier<Listener extends 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 and Description |
---|
Listeners() |
Modifier and Type | Method and Description |
---|---|
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).
|
Logger |
getLog()
Returns logger used by this object (null as default).
|
boolean |
isEqualListening(EventListener listener)
Returns true if at least one equals listener to the param 'listener' is found.
|
boolean |
isListening(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,
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(EventListener listener)
Removes all listeners that are equal() to this one.
|
int |
removeListener(EventListener listener)
Removes all listeners that are == to this one (not equal()! must be the same object).
|
void |
setLog(Logger log,
String name)
Sets logger for this object (logger is null by default).
|
public Logger getLog()
public void setLog(Logger log, String name)
log
- public void addStrongListener(Listener listener)
listener
- public void addWeakListener(Listener listener)
listener
- public int removeEqualListener(EventListener listener)
listener
- public int removeListener(EventListener listener)
listener
- public void notify(Listeners.ListenerNotifier<Listener> notifier)
notifier
- public boolean notifySafe(Listeners.ListenerNotifier<Listener> notifier, 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 nullpublic boolean isEqualListening(EventListener listener)
listener
- public boolean isListening(EventListener listener)
listener
- public void clearListeners()
public int count()
Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of used queue, determining the current number of elements requires an O(n) traversal.
public void remove(Listeners.ListenerRemover remover)
remover
- Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.