|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.logicalcobwebs.proxool.util.AbstractListenerContainer
Implementation of ListenerContainerIF
that uses a reads/write lock to handle concurrency in a safe and
fast way.
The registered listeners are offered to subclasses through the protected #getListenerIterator
method. This
method aquires a read lock before it returns the iterator, but it is the subclass responsibility to
release this lock by calling the #releaseReadLock
method. Failing to do this will prevent any more
listeneres to be added or removed. Your code sould look like this:
Iterator listenerIterator = null;
try {
listenerIterator = getListenerIterator();
if (listenerIterator != null) {
// ... Iterate through the listeners and notify them
}
} catch (InterruptedException e) {
LOG.error("Tried to aquire read lock for " + MyClass.class.getName()
+ " iterator but was interrupted.");
} finally {
releaseReadLock();
}
Constructor Summary | |
AbstractListenerContainer()
|
Method Summary | |
void |
addListener(java.lang.Object listener)
Add a listener to this container. |
boolean |
isEmpty()
Get wether this container is empty or not. |
boolean |
removeListener(java.lang.Object listener)
Remove a listener from this container. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AbstractListenerContainer()
Method Detail |
public void addListener(java.lang.Object listener)
ListenerContainerIF
addListener
in interface ListenerContainerIF
listener
- the listener to add.ListenerContainerIF.addListener(Object)
public boolean removeListener(java.lang.Object listener)
ListenerContainerIF
removeListener
in interface ListenerContainerIF
listener
- the listener to be removed.
ListenerContainerIF.removeListener(Object)
public boolean isEmpty()
ListenerContainerIF
isEmpty
in interface ListenerContainerIF
ListenerContainerIF.isEmpty()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |