@InterfaceAudience.Private @InterfaceStability.Evolving public class ConfigurationManager extends Object
If a class has configuration properties which you would like to be able to change on-the-fly, do the following:
ConfigurationObserver
interface. This would require you to implement
the ConfigurationObserver.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. ConfigurationManager
instance, using the registerObserver(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.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.Modifier and Type | Field and Description |
---|---|
private Set<ConfigurationObserver> |
configurationObservers |
private static org.slf4j.Logger |
LOG |
Constructor and Description |
---|
ConfigurationManager() |
Modifier and Type | Method and Description |
---|---|
void |
deregisterObserver(ConfigurationObserver observer)
Deregister an observer class
|
int |
getNumObservers()
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
|
private static final org.slf4j.Logger LOG
private final Set<ConfigurationObserver> configurationObservers
public ConfigurationManager()
public void registerObserver(ConfigurationObserver observer)
observer
- observer to be registered.public void deregisterObserver(ConfigurationObserver observer)
observer
- to be deregistered.public void notifyAllObservers(org.apache.hadoop.conf.Configuration conf)
public int getNumObservers()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.