JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit
Class ConfigChangeListenerTool

java.lang.Object
  |
  +--com.jthreadkit.ConfigChangeListenerTool
All Implemented Interfaces:
AccessibleLock

public class ConfigChangeListenerTool
extends Object
implements AccessibleLock

Used to add support for ConfigChangeListener's to a class. In most cases, an instance of this class is held in a private member variable and the methods are called internally when appropriate. Subclassing is discouraged.

This class can be used like this:
  
private ConfigChangeListenerTool configTool; // member variable

public //...
    // ... in a constructor ...
    configTool = new ConfigChangeListenerTool(this);
}

public void addConfigChangeListener(ConfigChangeListener listener) {
    configTool.addConfigChangeListener(listener);
}

public void removeConfigChangeListener(ConfigChangeListener listener) {
    configTool.removeConfigChangeListener(listener);
}

private void notifyConfigChangeListeners() {
    configTool.notifyConfigChangeListeners();
}

For a generic tool for managing listeners of any type, see ListenerTool.


Constructor Summary
ConfigChangeListenerTool(Object lock)
          Creates an instance for managing ConfigChangeListener's.
 
Method Summary
 boolean addConfigChangeListener(ConfigChangeListener listener)
          Adds a ConfigChangeListener to the list.
 Object getLockObject()
          Returns the reference to the object that is synchronized on by other methods in the implementing class.
 void notifyConfigChangeListeners()
          Causes the configChanged() method of all of the registered listeners to be called.
 boolean removeConfigChangeListener(ConfigChangeListener listener)
          Removes a ConfigChangeListener from the list.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigChangeListenerTool

public ConfigChangeListenerTool(Object lock)
Creates an instance for managing ConfigChangeListener's.
Parameters:
lock - the object to lock on for synchronization. If null then the instance itself it used.
Method Detail

getLockObject

public Object getLockObject()
Description copied from interface: AccessibleLock
Returns the reference to the object that is synchronized on by other methods in the implementing class. This reference is not permitted to change after construction, so this method can be called once and the reference saved.

This reference can be used in synchronized blocks to keep other threads from sneaking in between methods calls like this:
  
obj = //...
synchronized ( obj.getLockObject() ) {
    obj.methodA(); 
    obj.methodB(); 
}

Specified by:
getLockObject in interface AccessibleLock
Following copied from interface: com.jthreadkit.AccessibleLock
Returns:
the object used to lock on to control concurrent access.

addConfigChangeListener

public boolean addConfigChangeListener(ConfigChangeListener listener)
Adds a ConfigChangeListener to the list. Duplicates are ignored.
Parameters:
listener - the listener to add.
Returns:
true if the listener was added, false if it was not added because it is a duplicate.

removeConfigChangeListener

public boolean removeConfigChangeListener(ConfigChangeListener listener)
Removes a ConfigChangeListener from the list. Non-existent listeners are ignored.
Parameters:
listener - the listener to remove.
Returns:
true if the listener was removed, false if it was not removed because it was not found.

notifyConfigChangeListeners

public void notifyConfigChangeListeners()
Causes the configChanged() method of all of the registered listeners to be called. An exclusive lock on the object retruned from getLockObject() is held throughout this call while all listeners are notified.

JThreadKitTM
v1.1.0
(public members only)

© Copyright 2000-2001 Programix Incorporated. All rights reserved. JThreadKit home