@InterfaceAudience.Private @InterfaceStability.Evolving public class ConfigurationManager extends Object
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.
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.
2. Register the appropriate instance of the class with the
ConfigurationManager
instance, using the
registerObserver(ConfigurationObserver)
method. For the RS side of things, the ConfigurationManager is a static
member of the 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()
method which is called after the construction of the object.
3. 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.Modifier and Type | Field and Description |
---|---|
private Set<ConfigurationObserver> |
configurationObservers |
private static org.apache.commons.logging.Log |
LOG |
Constructor and Description |
---|
ConfigurationManager() |
Modifier and Type | Method and Description |
---|---|
void |
deregisterObserver(ConfigurationObserver observer)
Deregister an observer class
|
int |
getNumObservers() |
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.apache.commons.logging.Log LOG
private Set<ConfigurationObserver> configurationObservers
public void registerObserver(ConfigurationObserver observer)
observer
- public void deregisterObserver(ConfigurationObserver observer)
observer
- public void notifyAllObservers(org.apache.hadoop.conf.Configuration conf)
public int getNumObservers()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.