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 90b66544f0
commit ee869b9aea
No known key found for this signature in database
GPG Key ID: 18AE42A0B5A93FA7
4 changed files with 5 additions and 14 deletions

View File

@ -19,13 +19,10 @@ package org.apache.hadoop.hbase.conf;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
import org.apache.hadoop.conf.Configuration;
/**
* Maintains the set of all the classes which would like to get notified
@ -56,9 +53,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,10 +63,7 @@ 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
public class ConfigurationManager {
private static final Log LOG = LogFactory.getLog(ConfigurationManager.class);
@ -80,12 +72,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<ConfigurationObserver, Boolean>());
/**
* Register an observer class
* @param observer
* @param observer observer to be registered.
*/
public void registerObserver(ConfigurationObserver observer) {
synchronized (configurationObservers) {
@ -98,7 +89,7 @@ public class ConfigurationManager {
/**
* Deregister an observer class
* @param observer
* @param observer to be deregistered.
*/
public void deregisterObserver(ConfigurationObserver observer) {
synchronized (configurationObservers) {