Package org.apache.hadoop.hbase.conf
Class ConfigurationManager
java.lang.Object
org.apache.hadoop.hbase.conf.ConfigurationManager
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 Change mechanism, which lets you update
certain configuration properties on-the-fly, without having to restart the cluster.
If a class has configuration properties which you would like to be able to change on-the-fly, do the following:
- Implement the
ConfigurationObserver
interface. This would require you to implement theConfigurationObserver.onConfigurationChange(Configuration)
method. This is a callback that is used to notify your class' instance that the configuration has changed. In this method, you need to check if the new values for the properties that are of interest to your class are different from the cached values. If yes, update them.
However, be careful with this. Certain properties might be trivially mutable online, but others might not. Two properties might be trivially mutable by themselves, but not when changed together. For example, if a method uses properties "a" and "b" to make some decision, and is running in parallel when the notifyOnChange() method updates "a", but hasn't yet updated "b", it might make a decision on the basis of a new value of "a", and an old value of "b". This might introduce subtle bugs. This needs to be dealt on a case-by-case basis, and this class does not provide any protection from such cases. - Register the appropriate instance of the class with the
ConfigurationManager
instance, using theregisterObserver(ConfigurationObserver)
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. - Deregister the instance using the
deregisterObserver(ConfigurationObserver)
method when it is going out of scope. In case you are not able to do that 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.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final Set<ConfigurationObserver>
private static final org.slf4j.Logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deregisterObserver
(ConfigurationObserver observer) Deregister an observer classint
Returns the number of observers.void
notifyAllObservers
(org.apache.hadoop.conf.Configuration conf) The conf object has been repopulated from disk, and we have to notify all the observers that are expressed interest to do that.void
registerObserver
(ConfigurationObserver observer) Register an observer class
-
Field Details
-
LOG
-
configurationObservers
-
-
Constructor Details
-
ConfigurationManager
public ConfigurationManager()
-
-
Method Details
-
registerObserver
Register an observer class- Parameters:
observer
- observer to be registered.
-
deregisterObserver
Deregister an observer class- Parameters:
observer
- to be deregistered.
-
notifyAllObservers
The conf object has been repopulated from disk, and we have to notify all the observers that are expressed interest to do that. -
getNumObservers
Returns the number of observers.
-