Package org.apache.zookeeper.common
Class ZKConfig
- java.lang.Object
- 
- org.apache.zookeeper.common.ZKConfig
 
- 
- Direct Known Subclasses:
- ZKClientConfig
 
 public class ZKConfig extends Object This class is a base class for the configurations of both client and server. It supports reading client configuration from both system properties and configuration file. A user can override any system property by callingsetProperty(String, String).- Since:
- 3.5.2
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringJGSS_NATIVEstatic StringJUTE_MAXBUFFERstatic StringKINIT_COMMANDPath to a kinit binary: "zookeeper.kinit".
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConfiguration(File configFile)Add a configuration resource.voidaddConfiguration(String configPath)Add a configuration resource.booleangetBoolean(String key)Returnstrueif and only if the property named by the argument exists and is equal to the string"true".booleangetBoolean(String key, boolean defaultValue)Get the value of thekeyproperty as aboolean.intgetInt(String key, int defaultValue)Get the value of thekeyproperty as anint.StringgetJaasConfKey()Return the value of "java.security.auth.login.config" system propertyStringgetProperty(String key)Get the property valueStringgetProperty(String key, String defaultValue)Get the property value, if it is null return default valueprotected voidhandleBackwardCompatibility()Now onwards client code will use properties from this class but older clients still be setting properties through system properties.voidsetProperty(String key, String value)Maps the specifiedkeyto the specifiedvalue.
 
- 
- 
- 
Field Detail- 
JUTE_MAXBUFFERpublic static final String JUTE_MAXBUFFER - See Also:
- Constant Field Values
 
 - 
KINIT_COMMANDpublic static final String KINIT_COMMAND Path to a kinit binary: "zookeeper.kinit". Defaults to"/usr/bin/kinit"- See Also:
- Constant Field Values
 
 - 
JGSS_NATIVEpublic static final String JGSS_NATIVE - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ZKConfigpublic ZKConfig() properties, which are common to both client and server, are initialized from system properties
 - 
ZKConfigpublic ZKConfig(String configPath) throws QuorumPeerConfig.ConfigException - Parameters:
- configPath- Configuration file path
- Throws:
- QuorumPeerConfig.ConfigException- if failed to load configuration properties
 
 - 
ZKConfigpublic ZKConfig(File configFile) throws QuorumPeerConfig.ConfigException - Parameters:
- configFile- Configuration file
- Throws:
- QuorumPeerConfig.ConfigException- if failed to load configuration properties
 
 
- 
 - 
Method Detail- 
handleBackwardCompatibilityprotected void handleBackwardCompatibility() Now onwards client code will use properties from this class but older clients still be setting properties through system properties. So to make this change backward compatible we should set old system properties in this configuration.
 - 
getPropertypublic String getProperty(String key) Get the property value- Parameters:
- key-
- Returns:
- property value
 
 - 
getPropertypublic String getProperty(String key, String defaultValue) Get the property value, if it is null return default value- Parameters:
- key- property key
- defaultValue-
- Returns:
- property value or default value
 
 - 
getJaasConfKeypublic String getJaasConfKey() Return the value of "java.security.auth.login.config" system property- Returns:
- value
 
 - 
setPropertypublic void setProperty(String key, String value) Maps the specifiedkeyto the specifiedvalue. key can not benull. If key is already mapped then the old value of thekeyis replaced by the specifiedvalue.- Parameters:
- key-
- value-
 
 - 
addConfigurationpublic void addConfiguration(File configFile) throws QuorumPeerConfig.ConfigException Add a configuration resource. The properties form this configuration will overwrite corresponding already loaded property and system property- Parameters:
- configFile- Configuration file.
- Throws:
- QuorumPeerConfig.ConfigException
 
 - 
addConfigurationpublic void addConfiguration(String configPath) throws QuorumPeerConfig.ConfigException Add a configuration resource. The properties form this configuration will overwrite corresponding already loaded property and system property- Parameters:
- configPath- Configuration file path.
- Throws:
- QuorumPeerConfig.ConfigException
 
 - 
getBooleanpublic boolean getBoolean(String key) Returnstrueif and only if the property named by the argument exists and is equal to the string"true".
 - 
getBooleanpublic boolean getBoolean(String key, boolean defaultValue) Get the value of thekeyproperty as aboolean. Returnstrueif and only if the property named by the argument exists and is equal to the string"true". If the property is not set, the provideddefaultValueis returned.- Parameters:
- key- property key.
- defaultValue- default value.
- Returns:
- return property value as an boolean, ordefaultValue
 
 - 
getIntpublic int getInt(String key, int defaultValue) Get the value of thekeyproperty as anint. If property is not set, the provideddefaultValueis returned- Parameters:
- key- property key.
- defaultValue- default value.
- Returns:
- return property value as an int, ordefaultValue
- Throws:
- NumberFormatException- when the value is invalid
 
 
- 
 
-