Package org.apache.zookeeper.common
Class ZKConfig
java.lang.Object
org.apache.zookeeper.common.ZKConfig
- Direct Known Subclasses:
ZKClientConfig
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 calling
setProperty(String, String)
.- Since:
- 3.5.2
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfiguration
(File configFile) Add a configuration resource.void
addConfiguration
(String configPath) Add a configuration resource.boolean
getBoolean
(String key) Returnstrue
if and only if the property named by the argument exists and is equal to the string"true"
.boolean
getBoolean
(String key, boolean defaultValue) Get the value of thekey
property as aboolean
.int
Get the value of thekey
property as anint
.Return the value of "java.security.auth.login.config" system propertygetProperty
(String key) Get the property valuegetProperty
(String key, String defaultValue) Get the property value, if it is null return default valueprotected void
Now onwards client code will use properties from this class but older clients still be setting properties through system properties.void
setProperty
(String key, String value) Maps the specifiedkey
to the specifiedvalue
.
-
Field Details
-
JUTE_MAXBUFFER
- See Also:
-
KINIT_COMMAND
Path to a kinit binary: "zookeeper.kinit". Defaults to"/usr/bin/kinit"
- See Also:
-
JGSS_NATIVE
- See Also:
-
-
Constructor Details
-
ZKConfig
public ZKConfig()properties, which are common to both client and server, are initialized from system properties -
ZKConfig
- Parameters:
configPath
- Configuration file path- Throws:
QuorumPeerConfig.ConfigException
- if failed to load configuration properties
-
ZKConfig
- Parameters:
configFile
- Configuration file- Throws:
QuorumPeerConfig.ConfigException
- if failed to load configuration properties
-
-
Method Details
-
handleBackwardCompatibility
protected 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. -
getProperty
Get the property value- Parameters:
key
-- Returns:
- property value
-
getProperty
Get the property value, if it is null return default value- Parameters:
key
- property keydefaultValue
-- Returns:
- property value or default value
-
getJaasConfKey
Return the value of "java.security.auth.login.config" system property- Returns:
- value
-
setProperty
Maps the specifiedkey
to the specifiedvalue
. key can not benull
. If key is already mapped then the old value of thekey
is replaced by the specifiedvalue
.- Parameters:
key
-value
-
-
addConfiguration
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
-
addConfiguration
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
-
getBoolean
Returnstrue
if and only if the property named by the argument exists and is equal to the string"true"
. -
getBoolean
Get the value of thekey
property as aboolean
. Returnstrue
if and only if the property named by the argument exists and is equal to the string"true"
. If the property is not set, the provideddefaultValue
is returned.- Parameters:
key
- property key.defaultValue
- default value.- Returns:
- return property value as an
boolean
, ordefaultValue
-
getInt
Get the value of thekey
property as anint
. If property is not set, the provideddefaultValue
is returned- Parameters:
key
- property key.defaultValue
- default value.- Returns:
- return property value as an
int
, ordefaultValue
- Throws:
NumberFormatException
- when the value is invalid
-