From 4f49a9625801d28a27d4c034977e699a46d20cba Mon Sep 17 00:00:00 2001 From: Bharath Vissapragada Date: Sun, 31 May 2020 11:18:16 -0700 Subject: [PATCH] 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 Signed-off-by: Viraj Jasani --- .../hbase/conf/ConfigurationManager.java | 19 +++++++------------ .../hbase/conf/ConfigurationObserver.java | 0 .../PropagatingConfigurationObserver.java | 0 .../hbase/conf/TestConfigurationManager.java | 0 4 files changed, 7 insertions(+), 12 deletions(-) rename {hbase-server => hbase-common}/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java (93%) rename {hbase-server => hbase-common}/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationObserver.java (100%) rename {hbase-server => hbase-common}/src/main/java/org/apache/hadoop/hbase/conf/PropagatingConfigurationObserver.java (100%) rename {hbase-server => hbase-common}/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java (100%) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java similarity index 93% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java rename to hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java index 3e8d8fbacac..511679f5b54 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationManager.java @@ -17,6 +17,9 @@ */ 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.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; import org.apache.yetus.audience.InterfaceAudience; @@ -24,10 +27,6 @@ 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 @@ -57,9 +56,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. * @@ -69,7 +66,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 @@ -81,12 +77,11 @@ public class ConfigurationManager { // constructed from a WeakHashMap, whose entries would be removed if the // observer classes go out of scope. private final Set configurationObservers = - Collections.newSetFromMap(new WeakHashMap()); + Collections.newSetFromMap(new WeakHashMap<>()); /** * Register an observer class - * @param observer + * @param observer observer to be registered. */ public void registerObserver(ConfigurationObserver observer) { synchronized (configurationObservers) { @@ -99,7 +94,7 @@ public class ConfigurationManager { /** * Deregister an observer class - * @param observer + * @param observer to be deregistered. */ public void deregisterObserver(ConfigurationObserver observer) { synchronized (configurationObservers) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationObserver.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationObserver.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationObserver.java rename to hbase-common/src/main/java/org/apache/hadoop/hbase/conf/ConfigurationObserver.java diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/conf/PropagatingConfigurationObserver.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/conf/PropagatingConfigurationObserver.java similarity index 100% rename from hbase-server/src/main/java/org/apache/hadoop/hbase/conf/PropagatingConfigurationObserver.java rename to hbase-common/src/main/java/org/apache/hadoop/hbase/conf/PropagatingConfigurationObserver.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java similarity index 100% rename from hbase-server/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java rename to hbase-common/src/test/java/org/apache/hadoop/hbase/conf/TestConfigurationManager.java