org.logicalcobwebs.proxool.util
Class AbstractListenerContainer

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

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 getListeners() method. This method returns a reference to an array containing the registered listeners. A new array holding the listeners is created everytime a modification on the registration list is required (add/remove listener). Therefore, subclasses can safely iterate over the received array. Your code sould look like this:

     Object[] listeners = getListeners();
     for(int i=0; i
 
 

Since:
Proxool 0.7
Version:
$Revision: 1.8 $, $Date: 2004/03/16 08:48:33 $
Author:
Christian Nedregaard (christian_nedregaard@email.com), $Author: brenuart $ (current maintainer)

Field Summary
private static java.lang.Object[] EMPTY_LISTENERS
           
private  java.lang.Object[] listeners
           
 
Constructor Summary
AbstractListenerContainer()
           
 
Method Summary
 void addListener(java.lang.Object listener)
          Add a listener to this container.
protected  java.lang.Object[] getListeners()
          Get a reference to the array of registered listeners.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

private java.lang.Object[] listeners

EMPTY_LISTENERS

private static final java.lang.Object[] EMPTY_LISTENERS
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)

getListeners

protected java.lang.Object[] getListeners()
Get a reference to the array of registered listeners.

Returns:
reference to the array containing registered listeners (always not NULL)

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