|
JThreadKitTM v1.1.0 ( public members only)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.jthreadkit.ConfigChangeListenerTool
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 |
public ConfigChangeListenerTool(Object lock)
ConfigChangeListener's.lock - the object to lock on for synchronization. If
null then the instance itself it used.| Method Detail |
public Object getLockObject()
AccessibleLock
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();
}
|
getLockObject in interface AccessibleLockcom.jthreadkit.AccessibleLockpublic boolean addConfigChangeListener(ConfigChangeListener listener)
ConfigChangeListener to the list. Duplicates
are ignored.listener - the listener to add.true if the listener was added, false
if it was not added because it is a duplicate.public boolean removeConfigChangeListener(ConfigChangeListener listener)
ConfigChangeListener from the list. Non-existent
listeners are ignored.listener - the listener to remove.true if the listener was removed, false
if it was not removed because it was not found.public void notifyConfigChangeListeners()
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)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||