net.opentsdb.utils
public class Config extends Object
loadConfig()
methods to search for a
default configuration or try to load one provided by the user.
To add a configuration, simply set a default value in setDefaults()
.
Wherever you need to access the config value, use the proper helper to fetch
the value, accounting for exceptions that may be thrown if necessary.
The getgetString(String)
helper will return a NullPointerException if the property isn't found.
Plugins can extend this class and copy the properties from the main TSDB.config instance. Plugins should never change the main TSD's config properties, rather a plugin should use the Config(final Config parent) constructor to get a copy of the parent's properties and then work with the values locally.
Modifier and Type | Field and Description |
---|---|
protected static HashMap<String,String> |
default_map
Holds default values for the config
|
static boolean |
IS_WINDOWS
Flag to determine if we're running under Windows or not
|
protected HashMap<String,String> |
properties
The list of properties configured to their defaults or modified by users
|
Constructor and Description |
---|
Config(boolean auto_load_config)
Constructor that initializes default configuration values.
|
Config(Config parent)
Constructor for plugins or overloaders who want a copy of the parent
properties but without the ability to modify them
This constructor will not re-read the file, but it will copy the location
so if a child wants to reload the properties periodically, they may do so
|
Config(String file)
Constructor that initializes default values and attempts to load the given
properties file
|
Modifier and Type | Method and Description |
---|---|
boolean |
auto_metric() |
String |
dumpConfiguration()
Returns a simple string with the configured properties for debugging
|
boolean |
enable_chunked_requests() |
boolean |
enable_compactions() |
boolean |
enable_realtime_ts() |
boolean |
enable_realtime_uid() |
boolean |
enable_tree_processing() |
boolean |
enable_tsuid_incrementing() |
boolean |
enable_tsuid_tracking() |
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 propery is in the map
|
protected void |
loadConfig()
Searches a list of locations for a valid opentsdb.conf file
The config file must be a standard JAVA properties formatted file.
|
protected void |
loadConfig(String file)
Attempts to load the configuration from the given location
|
int |
max_chunked_requests() |
void |
overrideConfig(String property,
String value)
Allows for modifying properties after loading
WARNING: This should only be used on initialization and is meant for
command line overrides
|
void |
setAutoMetric(boolean auto_metric) |
protected void |
setDefaults()
Loads default entries that were not provided by a file or command line
This should be called in the constructor
|
public static final boolean IS_WINDOWS
protected final HashMap<String,String> properties
public Config(boolean auto_load_config) throws IOException
auto_load_config
- When set to true, attempts to search for a config
file in the default locationsIOException
- Thrown if unable to read or parse one of the default
config filespublic 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 boolean auto_metric()
public void setAutoMetric(boolean auto_metric)
auto_metric
- whether or not to auto create metricspublic boolean enable_compactions()
public boolean enable_realtime_ts()
public boolean enable_realtime_uid()
public boolean enable_tsuid_incrementing()
public boolean enable_tsuid_tracking()
public boolean enable_chunked_requests()
public int max_chunked_requests()
public boolean enable_tree_processing()
public 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 loadNullPointerException
- if the property did not existpublic final int getInt(String property)
property
- The property to loadNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final short getShort(String property)
property
- The property to loadNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final long getLong(String property)
property
- The property to loadNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final float getFloat(String property)
property
- The property to loadNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final double getDouble(String property)
property
- The property to loadNumberFormatException
- if the property could not be parsedNullPointerException
- if the property did not existpublic final boolean getBoolean(String property)
property
- The property to loadNullPointerException
- if the property was not foundpublic final String getDirectoryName(String property)
property
- The property to loadNullPointerException
- if the property was not foundpublic final boolean hasProperty(String property)
property
- The property to search forpublic final String dumpConfiguration()
protected void setDefaults()
protected void loadConfig() throws IOException
IOException
- Thrown if there was an issue reading a fileprotected 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 found