java.lang.Object org.apache.hadoop.conf.Configuration
public class Configuration
Provides access to configuration parameters.
ResourcesConfigurations are specified by resources. A resource contains a set of name/value pairs as XML data. Each resource is named by either a String
or by a Path
. If named by a String
, then the classpath is examined for a file with that name. If named by a Path
, then the local filesystem is examined directly, without referring to the classpath.
Unless explicitly turned off, Hadoop by default specifies two resources, loaded in-order from the classpath:
Configuration parameters may be declared final. Once a resource declares a value final, no subsequently-loaded resource can alter that value. For example, one might define a final parameter with:
<property> <name>dfs.client.buffer.dir</name> <value>/tmp/hadoop/dfs/client</value> <final>true</final> </property>Administrators typically define parameters as final in core-site.xml for values that user applications may not alter. Variable Expansion
Value strings are first processed for variable expansion. The available properties are:
System.getProperties()
.For example, if a configuration resource contains the following property definitions:
<property> <name>basedir</name> <value>/user/${user.name}</value> </property> <property> <name>tempdir</name> <value>${basedir}/tmp</value> </property>When conf.get("tempdir") is called, then ${basedir} will be resolved to another property in this Configuration, while ${user.name} would then ordinarily be resolved to the value of the System property with that name. Constructor Summary
Configuration()
Configuration(boolean loadDefaults)
Configuration(Configuration other)
static void
addDefaultResource(String name)
void
addResource(InputStream in)
void
addResource(Path file)
void
addResource(String name)
void
addResource(URL url)
void
clear()
static void
dumpConfiguration(Configuration config, Writer out)
Writer
The format of the output would be { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, key2.isFinal,key2.resource}... String
get(String name)
name
property, null
if no such property exists. String
get(String name, String defaultValue)
name
property. boolean
getBoolean(String name, boolean defaultValue)
name
property as a boolean
. Class<?>
getClass(String name, Class<?> defaultValue)
name
property as a Class
. <U> Class<? extends U>
getClass(String name, Class<? extends U> defaultValue, Class<U> xface)
name
property as a Class
implementing the interface specified by xface
. Class<?>
getClassByName(String name)
Class<?>[]
getClasses(String name, Class<?>... defaultValue)
name
property as an array of Class
. ClassLoader
getClassLoader()
ClassLoader
for this job. InputStream
getConfResourceAsInputStream(String name)
name
. Reader
getConfResourceAsReader(String name)
Reader
attached to the configuration resource with the given name
. <T extends Enum<T>>
T
getEnum(String name, T defaultValue)
File
getFile(String dirsProp, String path)
float
getFloat(String name, float defaultValue)
name
property as a float
. <U> List<U>
getInstances(String name, Class<U> xface)
name
property as a List
of objects implementing the interface specified by xface
. int
getInt(String name, int defaultValue)
name
property as an int
. Path
getLocalPath(String dirsProp, String path)
long
getLong(String name, long defaultValue)
name
property as a long
. Configuration.IntegerRanges
getRange(String name, String defaultValue)
String
getRaw(String name)
name
property, without doing variable expansion. URL
getResource(String name)
URL
for the named resource. Collection<String>
getStringCollection(String name)
name
property as a collection of String
s. String[]
getStrings(String name)
name
property as an array of String
s. String[]
getStrings(String name, String... defaultValue)
name
property as an array of String
s. Map<String,String>
getValByRegex(String regex)
Iterator<Map.Entry<String,String>>
iterator()
Iterator
to go through the list of String
key-value pairs in the configuration. static void
main(String[] args)
void
readFields(DataInput in)
in
. void
reloadConfiguration()
void
set(String name, String value)
value
of the name
property. void
setBoolean(String name, boolean value)
name
property to a boolean
. void
setBooleanIfUnset(String name, boolean value)
void
setClass(String name, Class<?> theClass, Class<?> xface)
name
property to the name of a theClass
implementing the given interface xface
. void
setClassLoader(ClassLoader classLoader)
<T extends Enum<T>>
void
setEnum(String name, T value)
name
property to the given type. void
setFloat(String name, float value)
name
property to a float
. void
setIfUnset(String name, String value)
void
setInt(String name, int value)
name
property to an int
. void
setLong(String name, long value)
name
property to a long
. void
setQuietMode(boolean quietmode)
void
setStrings(String name, String... values)
name
property as as comma delimited values. int
size()
String
toString()
void
unset(String name)
void
write(DataOutput out)
out
. void
writeXml(OutputStream out)
OutputStream
. void
writeXml(Writer out)
Writer
. Configuration
public Configuration()
public Configuration(boolean loadDefaults)
loadDefaults
is false, the new instance will not load resources from the default files.
loadDefaults
- specifies whether to load from the default files
public Configuration(Configuration other)
other
- the configuration from which to clone settings.
public static void addDefaultResource(String name)
name
- file name. File should be present in the classpath.
public void addResource(String name)
name
- resource to be added, the classpath is examined for a file with that name.
public void addResource(URL url)
url
- url of the resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
public void addResource(Path file)
file
- file-path of resource to be added, the local filesystem is examined directly to find the resource, without referring to the classpath.
public void addResource(InputStream in)
in
- InputStream to deserialize the object from.
public void reloadConfiguration()
public String get(String name)
name
property, null
if no such property exists. Values are processed for variable expansion before being returned.
name
- the property name.
name
property, or null if no such property exists.
public String getRaw(String name)
name
property, without doing variable expansion.
name
- the property name.
name
property, or null if no such property exists.
public void set(String name, String value)
value
of the name
property.
name
- property name.
value
- property value.
public void unset(String name)
public void setIfUnset(String name, String value)
name
- the property name
value
- the new value
public String get(String name, String defaultValue)
name
property. If no such property exists, then defaultValue
is returned.
name
- property name.
defaultValue
- default value.
defaultValue
if the property doesn't exist.
public int getInt(String name, int defaultValue)
name
property as an int
. If no such property exists, or if the specified value is not a valid int
, then defaultValue
is returned.
name
- property name.
defaultValue
- default value.
int
, or defaultValue
.
public void setInt(String name, int value)
name
property to an int
.
name
- property name.
value
- int
value of the property.
public long getLong(String name, long defaultValue)
name
property as a long
. If no such property is specified, or if the specified value is not a valid long
, then defaultValue
is returned.
name
- property name.
defaultValue
- default value.
long
, or defaultValue
.
public void setLong(String name, long value)
name
property to a long
.
name
- property name.
value
- long
value of the property.
public float getFloat(String name, float defaultValue)
name
property as a float
. If no such property is specified, or if the specified value is not a valid float
, then defaultValue
is returned.
name
- property name.
defaultValue
- default value.
float
, or defaultValue
.
public void setFloat(String name, float value)
name
property to a float
.
name
- property name.
value
- property value.
public boolean getBoolean(String name, boolean defaultValue)
name
property as a boolean
. If no such property is specified, or if the specified value is not a valid boolean
, then defaultValue
is returned.
name
- property name.
defaultValue
- default value.
boolean
, or defaultValue
.
public void setBoolean(String name, boolean value)
name
property to a boolean
.
name
- property name.
value
- boolean
value of the property.
public void setBooleanIfUnset(String name, boolean value)
name
- property name
value
- new value
public <T extends Enum<T>> void setEnum(String name, T value)
name
property to the given type. This is equivalent to set(<name>, value.toString())
.
name
- property name
value
- new value
public <T extends Enum<T>> T getEnum(String name, T defaultValue)
name
- Property name
defaultValue
- Value returned if no mapping exists
IllegalArgumentException
- If mapping is illegal for the type provided
public Configuration.IntegerRanges getRange(String name, String defaultValue)
name
- the attribute name
defaultValue
- the default value if it is not set
public Collection<String> getStringCollection(String name)
name
property as a collection of String
s. If no such property is specified then empty collection is returned.
This is an optimized version of getStrings(String)
name
- property name.
String
s.
public String[] getStrings(String name)
name
property as an array of String
s. If no such property is specified then null
is returned.
name
- property name.
String
s, or null
.
public String[] getStrings(String name, String... defaultValue)
name
property as an array of String
s. If no such property is specified then default value is returned.
name
- property name.
defaultValue
- The default value
String
s, or default value.
public void setStrings(String name, String... values)
name
property as as comma delimited values.
name
- property name.
values
- The values
public Class<?> getClassByName(String name) throws ClassNotFoundException
name
- the class name.
ClassNotFoundException
- if the class is not found.
public Class<?>[] getClasses(String name, Class<?>... defaultValue)
name
property as an array of Class
. The value of the property specifies a list of comma separated class names. If no such property is specified, then defaultValue
is returned.
name
- the property name.
defaultValue
- default value.
Class[]
, or defaultValue
.
public Class<?> getClass(String name, Class<?> defaultValue)
name
property as a Class
. If no such property is specified, then defaultValue
is returned.
name
- the class name.
defaultValue
- default value.
Class
, or defaultValue
.
public <U> Class<? extends U> getClass(String name, Class<? extends U> defaultValue, Class<U> xface)
name
property as a Class
implementing the interface specified by xface
. If no such property is specified, then defaultValue
is returned. An exception is thrown if the returned class does not implement the named interface.
name
- the class name.
defaultValue
- default value.
xface
- the interface implemented by the named class.
Class
, or defaultValue
.
public <U> List<U> getInstances(String name, Class<U> xface)
name
property as a List
of objects implementing the interface specified by xface
. An exception is thrown if any of the classes does not exist, or if it does not implement the named interface.
name
- the property name.
xface
- the interface implemented by the classes named by name
.
List
of objects implementing xface
.
public void setClass(String name, Class<?> theClass, Class<?> xface)
name
property to the name of a theClass
implementing the given interface xface
. An exception is thrown if theClass
does not implement the interface xface
.
name
- property name.
theClass
- property value.
xface
- the interface implemented by the named class.
public Path getLocalPath(String dirsProp, String path) throws IOException
dirsProp
- directory in which to locate the file.
path
- file-path.
IOException
public File getFile(String dirsProp, String path) throws IOException
dirsProp
- directory in which to locate the file.
path
- file-path.
IOException
public URL getResource(String name)
URL
for the named resource.
name
- resource name.
public InputStream getConfResourceAsInputStream(String name)
name
.
name
- configuration resource name.
public Reader getConfResourceAsReader(String name)
Reader
attached to the configuration resource with the given name
.
name
- configuration resource name.
public int size()
public void clear()
public Iterator<Map.Entry<String,String>> iterator()
Iterator
to go through the list of String
key-value pairs in the configuration.
iterator
in interface Iterable<Map.Entry<String,String>>
public void writeXml(OutputStream out) throws IOException
OutputStream
.
out
- the output stream to write to.
IOException
public void writeXml(Writer out) throws IOException
Writer
.
out
- the writer to write to.
IOException
public static void dumpConfiguration(Configuration config, Writer out) throws IOException
Writer
The format of the output would be { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2, key2.isFinal,key2.resource}... ] } It does not output the parameters of the configuration object which is loaded from an input stream.
out
- the Writer to write to
IOException
public ClassLoader getClassLoader()
ClassLoader
for this job.
public void setClassLoader(ClassLoader classLoader)
classLoader
- the new class loader.
public String toString()
toString
in class Object
public void setQuietMode(boolean quietmode)
quietmode
- true
to set quiet-mode on, false
to turn it off.
public static void main(String[] args) throws Exception
Exception
public void readFields(DataInput in) throws IOException
Writable
in
.
For efficiency, implementations should attempt to re-use storage in the existing object where possible.
readFields
in interface Writable
in
- DataInput
to deseriablize this object from.
IOException
public void write(DataOutput out) throws IOException
Writable
out
.
write
in interface Writable
out
- DataOuput
to serialize this object into.
IOException
public Map<String,String> getValByRegex(String regex)
regex
-
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4