Class Configuration
- java.lang.Object
-
- java.util.Observable
-
- org.torproject.metrics.collector.conf.Configuration
-
- All Implemented Interfaces:
java.lang.Cloneable
public class Configuration extends java.util.Observable implements java.lang.Cloneable
Initialize configuration with defaults from collector.properties, unless a configuration properties file is available.
-
-
Constructor Summary
Constructors Constructor Description Configuration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
clears all properties.boolean
getBool(Key key)
Returns aboolean
property (case insensitiv), e.g.int
getInt(Key key)
Parse an integer property and translate the String"inf"
into Integer.MAX_VALUE.long
getLong(Key key)
Parse a long property.java.nio.file.Path
getPath(Key key)
Returns aPath
property, e.g.java.util.Properties
getPropertiesCopy()
Return a copy of all properties.java.lang.String
getProperty(java.lang.String key)
Retrieves the value for key.java.lang.String
getProperty(java.lang.String key, java.lang.String def)
Retrieves the value for key returning a default for non-existing keys.java.util.Set<SourceType>
getSourceTypeSet(Key key)
Returns aSourceType
as List, e.g.java.lang.String[]
getStringArray(Key key)
ReturnsString[]
from a property.java.lang.String[][]
getStringArrayArray(Key key)
ReturnsString[][]
from a property.java.net.URL
getUrl(Key key)
Returns aURL
property, e.g.java.net.URL[]
getUrlArray(Key key)
ReturnsURL[]
from a property.void
load(java.io.InputStream fis)
Loads properties from the given stream.void
putAll(java.util.Properties allProps)
Add all given properties.void
setProperty(java.lang.String key, java.lang.String value)
Sets the value for key.void
setWatchableSourceAndLoad(java.nio.file.Path confPath)
Load the configuration from the given path and start monitoring changes.int
size()
Count of properties.
-
-
-
Field Detail
-
FIELDSEP
public static final java.lang.String FIELDSEP
- See Also:
- Constant Field Values
-
ARRAYSEP
public static final java.lang.String ARRAYSEP
- See Also:
- Constant Field Values
-
-
Method Detail
-
setWatchableSourceAndLoad
public void setWatchableSourceAndLoad(java.nio.file.Path confPath) throws ConfigurationException
Load the configuration from the given path and start monitoring changes. If the file was changed, re-read and inform all observers.- Throws:
ConfigurationException
-
getPropertiesCopy
public java.util.Properties getPropertiesCopy()
Return a copy of all properties.
-
load
public void load(java.io.InputStream fis) throws java.io.IOException
Loads properties from the given stream.- Throws:
java.io.IOException
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Retrieves the value for key.
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String def)
Retrieves the value for key returning a default for non-existing keys.
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value)
Sets the value for key.
-
clear
public void clear()
clears all properties.
-
putAll
public void putAll(java.util.Properties allProps)
Add all given properties.
-
size
public int size()
Count of properties.
-
getStringArrayArray
public java.lang.String[][] getStringArrayArray(Key key) throws ConfigurationException
ReturnsString[][]
from a property. Commas seperate array elements and semicolons separate arrays, e.g.,propertyname = a1, a2, a3; b1, b2, b3
- Throws:
ConfigurationException
-
getStringArray
public java.lang.String[] getStringArray(Key key) throws ConfigurationException
ReturnsString[]
from a property. Commas seperate array elements, e.g.,propertyname = a1, a2, a3
- Throws:
ConfigurationException
-
getBool
public boolean getBool(Key key) throws ConfigurationException
Returns aboolean
property (case insensitiv), e.g.propertyOne = True
.- Throws:
ConfigurationException
-
getInt
public int getInt(Key key) throws ConfigurationException
Parse an integer property and translate the String"inf"
into Integer.MAX_VALUE. Verifies that this enum is a Key for an integer value.- Throws:
ConfigurationException
-
getLong
public long getLong(Key key) throws ConfigurationException
Parse a long property. Verifies that this enum is a Key for a Long value.- Throws:
ConfigurationException
-
getPath
public java.nio.file.Path getPath(Key key) throws ConfigurationException
Returns aPath
property, e.g.pathProperty = /my/path/file
.- Throws:
ConfigurationException
-
getSourceTypeSet
public java.util.Set<SourceType> getSourceTypeSet(Key key) throws ConfigurationException
Returns aSourceType
as List, e.g.sourcetypeproperty = Remote, Sync
.- Throws:
ConfigurationException
-
getUrl
public java.net.URL getUrl(Key key) throws ConfigurationException
Returns aURL
property, e.g.urlProperty = https://my.url.here
.- Throws:
ConfigurationException
-
getUrlArray
public java.net.URL[] getUrlArray(Key key) throws ConfigurationException
ReturnsURL[]
from a property. Commas seperate array elements, e.g.,propertyname = a1.example.org, a2.example2.com, a3.example3.net
- Throws:
ConfigurationException
-
-