public class Config extends Object
loadSystemAndDefaults
will be called
to set defaults and optionally load values from the System properties list.
Note that multiple threads can read from this config object but modifying values is not thread safe.
Modifier and Type | Field and Description |
---|---|
protected String |
config_location
Tracks the location of the file that was actually loaded
|
protected HashMap<String,String> |
default_map
Holds default values for the config
|
protected HashMap<String,String> |
properties
The list of properties configured to their defaults or modified by users.
|
static boolean |
RUNNING_WINDOWS
Flag to determine if we're running under Windows or not
|
Constructor and Description |
---|
Config()
Constructor that initializes default configuration values from the
System.properties map.
|
Config(Config parent)
Constructor for subclasses who want a copy of the parent config but without
the ability to modify the original values.
|
Config(String file)
Constructor that initializes default values and attempts to load the given
properties file
|
Modifier and Type | Method and Description |
---|---|
String |
dumpConfiguration()
Returns a simple string with the configured properties for debugging.
|
boolean |
getBoolean(String property)
Returns the given property as a boolean
Property values are case insensitive and the following values will result
in a True return value: - 1 - True - Yes
Any other values, including an empty string, will result in a False
|
String |
getDirectoryName(String property)
Returns the directory name, making sure the end is an OS dependent slash
|
double |
getDouble(String property)
Returns the given property as a double
|
float |
getFloat(String property)
Returns the given property as a float
|
int |
getInt(String property)
Returns the given property as an integer
|
long |
getLong(String property)
Returns the given property as a long
|
Map<String,String> |
getMap() |
short |
getShort(String property)
Returns the given property as a short
|
String |
getString(String property)
Returns the given property as a String
|
boolean |
hasProperty(String property)
Determines if the given property is in the map
|
protected void |
loadConfig(String file)
Attempts to load the configuration from the given location
|
void |
overrideConfig(String property,
String value)
Allows for modifying properties after loading
WARNING: This should only be used on initialization of the config object
and it is not thread safe.
|
public static final boolean RUNNING_WINDOWS
protected final HashMap<String,String> properties
protected String config_location
public Config()
public Config(String file) throws IOException
file
- Path to the file to loadIOException
- Thrown if unable to read or parse the filepublic Config(Config parent)
parent
- Parent configuration object to load frompublic void overrideConfig(String property, String value)
property
- The name of the property to overridevalue
- The value to storepublic final String getString(String property)
property
- The property to fetchpublic final int getInt(String property)
property
- The property to fetchNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final short getShort(String property)
property
- The property to fetchNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final long getLong(String property)
property
- The property to fetchNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final float getFloat(String property)
property
- The property to fetchNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final double getDouble(String property)
property
- The property to fetchNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final boolean getBoolean(String property)
property
- The property to fetchNullPointerException
- if the property was not foundpublic final String getDirectoryName(String property)
property
- The property to fetchNullPointerException
- if the property was not foundpublic final boolean hasProperty(String property)
property
- The property to search forpublic final String dumpConfiguration()
protected void loadConfig(String file) throws FileNotFoundException, IOException
file
- Path to the file to loadIOException
- Thrown if there was an issue reading the fileFileNotFoundException
- Thrown if the config file was not foundCopyright © 2010-2017, The Async HBase Authors