HBASE-24477: Move ConfigurationObserver and related classes to hbase-common (#1815)
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:
parent
b4a4debdd9
commit
4f49a96258
|
@ -17,6 +17,9 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.conf;
|
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.hadoop.conf.Configuration;
|
||||||
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
@ -24,10 +27,6 @@ import org.apache.yetus.audience.InterfaceStability;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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
|
* 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
|
* when the Configuration is reloaded from the disk in the Online Configuration
|
||||||
|
@ -57,9 +56,7 @@ import java.util.WeakHashMap;
|
||||||
* 2. Register the appropriate instance of the class with the
|
* 2. Register the appropriate instance of the class with the
|
||||||
* {@link ConfigurationManager} instance, using the
|
* {@link ConfigurationManager} instance, using the
|
||||||
* {@link ConfigurationManager#registerObserver(ConfigurationObserver)}
|
* {@link ConfigurationManager#registerObserver(ConfigurationObserver)}
|
||||||
* method. For the RS side of things, the ConfigurationManager is a static
|
* method. Be careful not to do this in the constructor, as you might cause
|
||||||
* member of the {@link org.apache.hadoop.hbase.regionserver.HRegionServer}
|
|
||||||
* class. 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()
|
* the 'this' reference to escape. Use a factory method, or an initialize()
|
||||||
* method which is called after the construction of the object.
|
* method which is called after the construction of the object.
|
||||||
*
|
*
|
||||||
|
@ -69,7 +66,6 @@ import java.util.WeakHashMap;
|
||||||
* for any reason, it is still okay, since entries for dead observers are
|
* for any reason, it is still okay, since entries for dead observers are
|
||||||
* automatically collected during GC. But nonetheless, it is still a good
|
* automatically collected during GC. But nonetheless, it is still a good
|
||||||
* practice to deregister your observer, whenever possible.
|
* practice to deregister your observer, whenever possible.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
@InterfaceStability.Evolving
|
@InterfaceStability.Evolving
|
||||||
|
@ -81,12 +77,11 @@ public class ConfigurationManager {
|
||||||
// constructed from a WeakHashMap, whose entries would be removed if the
|
// constructed from a WeakHashMap, whose entries would be removed if the
|
||||||
// observer classes go out of scope.
|
// observer classes go out of scope.
|
||||||
private final Set<ConfigurationObserver> configurationObservers =
|
private final Set<ConfigurationObserver> configurationObservers =
|
||||||
Collections.newSetFromMap(new WeakHashMap<ConfigurationObserver,
|
Collections.newSetFromMap(new WeakHashMap<>());
|
||||||
Boolean>());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register an observer class
|
* Register an observer class
|
||||||
* @param observer
|
* @param observer observer to be registered.
|
||||||
*/
|
*/
|
||||||
public void registerObserver(ConfigurationObserver observer) {
|
public void registerObserver(ConfigurationObserver observer) {
|
||||||
synchronized (configurationObservers) {
|
synchronized (configurationObservers) {
|
||||||
|
@ -99,7 +94,7 @@ public class ConfigurationManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deregister an observer class
|
* Deregister an observer class
|
||||||
* @param observer
|
* @param observer to be deregistered.
|
||||||
*/
|
*/
|
||||||
public void deregisterObserver(ConfigurationObserver observer) {
|
public void deregisterObserver(ConfigurationObserver observer) {
|
||||||
synchronized (configurationObservers) {
|
synchronized (configurationObservers) {
|
Loading…
Reference in New Issue