HBASE-24477: Move ConfigurationObserver and related classes to hbase-common

This utility is useful for any module that wants to detect
dynamic config changes. Having it to hbase-common makes it
accessible to all the other modules.

Signed-off-by: Michael Stack <stack@apache.org>
Signed-off-by: Viraj Jasani <vjasani@apache.org>
This commit is contained in:
Bharath Vissapragada 2019-12-13 15:53:33 -08:00
parent 327d090e1b
commit d7f388518c
No known key found for this signature in database
GPG Key ID: 18AE42A0B5A93FA7
4 changed files with 7 additions and 12 deletions

View File

@ -17,16 +17,15 @@
*/
package org.apache.hadoop.hbase.conf;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
import org.apache.hadoop.conf.Configuration;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
/**
* Maintains the set of all the classes which would like to get notified
* when the Configuration is reloaded from the disk in the Online Configuration
@ -56,9 +55,7 @@ import java.util.WeakHashMap;
* 2. Register the appropriate instance of the class with the
* {@link ConfigurationManager} instance, using the
* {@link ConfigurationManager#registerObserver(ConfigurationObserver)}
* method. For the RS side of things, the ConfigurationManager is a static
* member of the {@link org.apache.hadoop.hbase.regionserver.HRegionServer}
* class. Be careful not to do this in the constructor, as you might cause
* method. Be careful not to do this in the constructor, as you might cause
* the 'this' reference to escape. Use a factory method, or an initialize()
* method which is called after the construction of the object.
*
@ -68,7 +65,6 @@ import java.util.WeakHashMap;
* for any reason, it is still okay, since entries for dead observers are
* automatically collected during GC. But nonetheless, it is still a good
* practice to deregister your observer, whenever possible.
*
*/
@InterfaceAudience.Private
@InterfaceStability.Evolving
@ -80,12 +76,11 @@ public class ConfigurationManager {
// constructed from a WeakHashMap, whose entries would be removed if the
// observer classes go out of scope.
private final Set<ConfigurationObserver> configurationObservers =
Collections.newSetFromMap(new WeakHashMap<ConfigurationObserver,
Boolean>());
Collections.newSetFromMap(new WeakHashMap<>());
/**
* Register an observer class
* @param observer
* @param observer observer to be registered.
*/
public void registerObserver(ConfigurationObserver observer) {
synchronized (configurationObservers) {
@ -98,7 +93,7 @@ public class ConfigurationManager {
/**
* Deregister an observer class
* @param observer
* @param observer to be deregistered.
*/
public void deregisterObserver(ConfigurationObserver observer) {
synchronized (configurationObservers) {