# 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 calling `setProperty(String, String)`.

Since:
  3.5.2

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`JGSS_NATIVE`
`static final String`
`JUTE_MAXBUFFER`
`static final String`
`KINIT_COMMAND`
Path to a kinit binary: "zookeeper.kinit".

## Constructor Summary

Constructors
Constructor
Description
`ZKConfig()`
properties, which are common to both client and server, are initialized from system properties
`ZKConfig(File configFile)`
Deprecated.
`ZKConfig(String configPath)`
Deprecated.
`ZKConfig(Path configPath)`
Constructs a `ZKConfig` with properties from file.

## Method Summary

Modifier and Type
Method
Description
`void`
`addConfiguration(File configFile)`
Deprecated.
`void`
`addConfiguration(String configPath)`
Deprecated.
`void`
`addConfiguration(Path configPath)`
Add a configuration resource.
`boolean`
`getBoolean(String key)`
Returns `true` 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 the `key` property as a `boolean`.
`int`
`getInt(String key, int defaultValue)`
Get the value of the `key` property as an `int`.
`String`
`getJaasConfKey()`
Return the value of "java.security.auth.login.config" system property
`String`
`getProperty(String key)`
Get the property value
`String`
`getProperty(String key, String defaultValue)`
Get the property value, if it is null return default value
`protected void`
`handleBackwardCompatibility()`
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 specified `key` to the specified `value`.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### JUTE_MAXBUFFER

public static final String JUTE_MAXBUFFER

See Also:
  - Constant Field Values

### KINIT_COMMAND

public static final String KINIT_COMMAND
Path to a kinit binary: "zookeeper.kinit". Defaults to `"/usr/bin/kinit"`

See Also:
  - Constant Field Values

### JGSS_NATIVE

public static final String JGSS_NATIVE

See Also:
  - Constant Field Values

## Constructor Details

### ZKConfig

public ZKConfig()
properties, which are common to both client and server, are initialized from system properties

### ZKConfig

@Deprecated public ZKConfig(String configPath) throws QuorumPeerConfig.ConfigException
Deprecated.

Use `ZKConfig(Path configPath)` instead.

The signature of this method will be changed to throw `ConfigException` instead of `QuorumPeerConfig.ConfigException` in future release.

Parameters:
  `configPath` - Configuration file path
Throws:
  `ConfigException` - if failed to load configuration properties
  `QuorumPeerConfig.ConfigException`

### ZKConfig

@Deprecated public ZKConfig(File configFile) throws QuorumPeerConfig.ConfigException
Deprecated.

Use `ZKConfig(Path configPath)` instead.

The signature of this method will be changed to throw `ConfigException` instead of `QuorumPeerConfig.ConfigException` in future release.

Parameters:
  `configFile` - Configuration file
Throws:
  `ConfigException` - if failed to load configuration properties
  `QuorumPeerConfig.ConfigException`

### ZKConfig

public ZKConfig(Path configPath) throws ConfigException
Constructs a `ZKConfig` with properties from file.

Parameters:
  `configPath` - path to configuration file
Throws:
  `ConfigException`

## 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

public String getProperty(String key)
Get the property value

Parameters:
  `key` -
Returns:
  property value

### getProperty

public 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

### getJaasConfKey

public String getJaasConfKey()
Return the value of "java.security.auth.login.config" system property

Returns:
  value

### setProperty

public void setProperty(String key, String value)
Maps the specified `key` to the specified `value`. key can not be `null`. If key is already mapped then the old value of the `key` is replaced by the specified `value`.

Parameters:
  `key` -
  `value` -

### addConfiguration

public void addConfiguration(Path configPath) throws ConfigException
Add a configuration resource. The properties form this configuration will overwrite corresponding already loaded property and system property

Parameters:
  `configPath` - path to Configuration file.
Throws:
  `ConfigException`

### addConfiguration

@Deprecated public void addConfiguration(File configFile) throws QuorumPeerConfig.ConfigException
Deprecated.

Use `addConfiguration(Path)` instead.

The signature of this method will be changed to throw `ConfigException` instead of `QuorumPeerConfig.ConfigException` in future release.

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

@Deprecated public void addConfiguration(String configPath) throws QuorumPeerConfig.ConfigException
Deprecated.

Use `addConfiguration(Path)` instead.

The signature of this method will be changed to throw `ConfigException` instead of `QuorumPeerConfig.ConfigException` in future release.

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

public boolean getBoolean(String key)
Returns `true` if and only if the property named by the argument exists and is equal to the string `"true"`.

### getBoolean

public boolean getBoolean(String key, boolean defaultValue)
Get the value of the `key` property as a `boolean`. Returns `true` 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 provided `defaultValue` is returned.

Parameters:
  `key` - property key.
  `defaultValue` - default value.
Returns:
  return property value as an `boolean`, or `defaultValue`

### getInt

public int getInt(String key, int defaultValue)
Get the value of the `key` property as an `int`. If property is not set, the provided `defaultValue` is returned

Parameters:
  `key` - property key.
  `defaultValue` - default value.
Returns:
  return property value as an `int`, or `defaultValue`
Throws:
  `NumberFormatException` - when the value is invalid