org.logicalcobwebs.proxool.util
Class AbstractListenerContainer

java.lang.Object
  extended byorg.logicalcobwebs.proxool.util.AbstractListenerContainer
All Implemented Interfaces:
ListenerContainerIF
Direct Known Subclasses:
CompositeConfigurationListener, CompositeConnectionListener, CompositeProxoolListener, CompositeStateListener, CompositeStatisticsListener

public abstract class AbstractListenerContainer
extends java.lang.Object
implements ListenerContainerIF

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();
     }
 

Since:
Proxool 0.7
Version:
$Revision: 1.7 $, $Date: 2003/03/11 00:12:11 $
Author:
Christian Nedregaard (christian_nedregaard@email.com), $Author: billhorsman $ (current maintainer)

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

AbstractListenerContainer

public AbstractListenerContainer()
Method Detail

addListener

public void addListener(java.lang.Object listener)
Description copied from interface: ListenerContainerIF
Add a listener to this container.

Specified by:
addListener in interface ListenerContainerIF
Parameters:
listener - the listener to add.
See Also:
ListenerContainerIF.addListener(Object)

removeListener

public boolean removeListener(java.lang.Object listener)
Description copied from interface: ListenerContainerIF
Remove a listener from this container.

Specified by:
removeListener in interface ListenerContainerIF
Parameters:
listener - the listener to be removed.
Returns:
wether the listnener was found and removed or not.
See Also:
ListenerContainerIF.removeListener(Object)

isEmpty

public boolean isEmpty()
Description copied from interface: ListenerContainerIF
Get wether this container is empty or not.

Specified by:
isEmpty in interface ListenerContainerIF
Returns:
wether this container is empty or not.
See Also:
ListenerContainerIF.isEmpty()