|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.conf.Configuration
public class Configuration
Provides access to configuration parameters.
Configurations 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.
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.
Nested Class Summary | |
---|---|
static class |
Configuration.IntegerRanges
A class that represents a set of positive integer ranges. |
Constructor Summary | |
---|---|
Configuration()
A new configuration. |
|
Configuration(boolean loadDefaults)
A new configuration where the behavior of reading from the default resources can be turned off. |
|
Configuration(Configuration other)
A new configuration with the same settings cloned from another. |
Method Summary | ||
---|---|---|
static void |
addDefaultResource(java.lang.String name)
Add a default resource. |
|
void |
addResource(java.io.InputStream in)
Add a configuration resource. |
|
void |
addResource(Path file)
Add a configuration resource. |
|
void |
addResource(java.lang.String name)
Add a configuration resource. |
|
void |
addResource(java.net.URL url)
Add a configuration resource. |
|
void |
clear()
Clears all keys from the configuration. |
|
java.lang.String |
get(java.lang.String name)
Get the value of the name property, null if
no such property exists. |
|
java.lang.String |
get(java.lang.String name,
java.lang.String defaultValue)
Get the value of the name property. |
|
boolean |
getBoolean(java.lang.String name,
boolean defaultValue)
Get the value of the name property as a boolean . |
|
java.lang.Class<?> |
getClass(java.lang.String name,
java.lang.Class<?> defaultValue)
Get the value of the name property as a Class . |
|
|
getClass(java.lang.String name,
java.lang.Class<? extends U> defaultValue,
java.lang.Class<U> xface)
Get the value of the name property as a Class
implementing the interface specified by xface . |
|
java.lang.Class<?> |
getClassByName(java.lang.String name)
Load a class by name. |
|
java.lang.Class<?>[] |
getClasses(java.lang.String name,
java.lang.Class<?>... defaultValue)
Get the value of the name property
as an array of Class . |
|
java.lang.ClassLoader |
getClassLoader()
Get the ClassLoader for this job. |
|
java.io.InputStream |
getConfResourceAsInputStream(java.lang.String name)
Get an input stream attached to the configuration resource with the given name . |
|
java.io.Reader |
getConfResourceAsReader(java.lang.String name)
Get a Reader attached to the configuration resource with the
given name . |
|
java.io.File |
getFile(java.lang.String dirsProp,
java.lang.String path)
Get a local file name under a directory named in dirsProp with the given path. |
|
float |
getFloat(java.lang.String name,
float defaultValue)
Get the value of the name property as a float . |
|
int |
getInt(java.lang.String name,
int defaultValue)
Get the value of the name property as an int . |
|
Path |
getLocalPath(java.lang.String dirsProp,
java.lang.String path)
Get a local file under a directory named by dirsProp with the given path. |
|
long |
getLong(java.lang.String name,
long defaultValue)
Get the value of the name property as a long . |
|
Configuration.IntegerRanges |
getRange(java.lang.String name,
java.lang.String defaultValue)
Parse the given attribute as a set of integer ranges |
|
java.lang.String |
getRaw(java.lang.String name)
Get the value of the name property, without doing
variable expansion. |
|
java.net.URL |
getResource(java.lang.String name)
Get the URL for the named resource. |
|
java.util.Collection<java.lang.String> |
getStringCollection(java.lang.String name)
Get the comma delimited values of the name property as
a collection of String s. |
|
java.lang.String[] |
getStrings(java.lang.String name)
Get the comma delimited values of the name property as
an array of String s. |
|
java.lang.String[] |
getStrings(java.lang.String name,
java.lang.String... defaultValue)
Get the comma delimited values of the name property as
an array of String s. |
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
iterator()
Get an Iterator to go through the list of String
key-value pairs in the configuration. |
|
static void |
main(java.lang.String[] args)
For debugging. |
|
void |
readFields(java.io.DataInput in)
Deserialize the fields of this object from in . |
|
void |
reloadConfiguration()
Reload configuration from previously added resources. |
|
void |
set(java.lang.String name,
java.lang.String value)
Set the value of the name property. |
|
void |
setBoolean(java.lang.String name,
boolean value)
Set the value of the name property to a boolean . |
|
void |
setBooleanIfUnset(java.lang.String name,
boolean value)
Set the given property, if it is currently unset. |
|
void |
setClass(java.lang.String name,
java.lang.Class<?> theClass,
java.lang.Class<?> xface)
Set the value of the name property to the name of a
theClass implementing the given interface xface . |
|
void |
setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader that will be used to load the various objects. |
|
void |
setFloat(java.lang.String name,
float value)
Set the value of the name property to a float . |
|
void |
setIfUnset(java.lang.String name,
java.lang.String value)
Sets a property if it is currently unset. |
|
void |
setInt(java.lang.String name,
int value)
Set the value of the name property to an int . |
|
void |
setLong(java.lang.String name,
long value)
Set the value of the name property to a long . |
|
void |
setQuietMode(boolean quietmode)
Set the quietness-mode. |
|
void |
setStrings(java.lang.String name,
java.lang.String... values)
Set the array of string values for the name property as
as comma delimited values. |
|
int |
size()
Return the number of keys in the configuration. |
|
java.lang.String |
toString()
|
|
void |
write(java.io.DataOutput out)
Serialize the fields of this object to out . |
|
void |
writeXml(java.io.OutputStream out)
Write out the non-default properties in this configuration to the give OutputStream . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
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 filespublic Configuration(Configuration other)
other
- the configuration from which to clone settings.Method Detail |
---|
public static void addDefaultResource(java.lang.String name)
name
- file name. File should be present in the classpath.public void addResource(java.lang.String name)
name
- resource to be added, the classpath is examined for a file
with that name.public void addResource(java.net.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(java.io.InputStream in)
in
- InputStream to deserialize the object from.public void reloadConfiguration()
public java.lang.String get(java.lang.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 java.lang.String getRaw(java.lang.String name)
name
property, without doing
variable expansion.
name
- the property name.
name
property,
or null if no such property exists.public void set(java.lang.String name, java.lang.String value)
value
of the name
property.
name
- property name.value
- property value.public void setIfUnset(java.lang.String name, java.lang.String value)
name
- the property namevalue
- the new valuepublic java.lang.String get(java.lang.String name, java.lang.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(java.lang.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(java.lang.String name, int value)
name
property to an int
.
name
- property name.value
- int
value of the property.public long getLong(java.lang.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(java.lang.String name, long value)
name
property to a long
.
name
- property name.value
- long
value of the property.public float getFloat(java.lang.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(java.lang.String name, float value)
name
property to a float
.
name
- property name.value
- property value.public boolean getBoolean(java.lang.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(java.lang.String name, boolean value)
name
property to a boolean
.
name
- property name.value
- boolean
value of the property.public void setBooleanIfUnset(java.lang.String name, boolean value)
name
- property namevalue
- new valuepublic Configuration.IntegerRanges getRange(java.lang.String name, java.lang.String defaultValue)
name
- the attribute namedefaultValue
- the default value if it is not set
public java.util.Collection<java.lang.String> getStringCollection(java.lang.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 java.lang.String[] getStrings(java.lang.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 java.lang.String[] getStrings(java.lang.String name, java.lang.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(java.lang.String name, java.lang.String... values)
name
property as
as comma delimited values.
name
- property name.values
- The valuespublic java.lang.Class<?> getClassByName(java.lang.String name) throws java.lang.ClassNotFoundException
name
- the class name.
java.lang.ClassNotFoundException
- if the class is not found.public java.lang.Class<?>[] getClasses(java.lang.String name, java.lang.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 java.lang.Class<?> getClass(java.lang.String name, java.lang.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> java.lang.Class<? extends U> getClass(java.lang.String name, java.lang.Class<? extends U> defaultValue, java.lang.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 void setClass(java.lang.String name, java.lang.Class<?> theClass, java.lang.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(java.lang.String dirsProp, java.lang.String path) throws java.io.IOException
dirsProp
- directory in which to locate the file.path
- file-path.
java.io.IOException
public java.io.File getFile(java.lang.String dirsProp, java.lang.String path) throws java.io.IOException
dirsProp
- directory in which to locate the file.path
- file-path.
java.io.IOException
public java.net.URL getResource(java.lang.String name)
URL
for the named resource.
name
- resource name.
public java.io.InputStream getConfResourceAsInputStream(java.lang.String name)
name
.
name
- configuration resource name.
public java.io.Reader getConfResourceAsReader(java.lang.String name)
Reader
attached to the configuration resource with the
given name
.
name
- configuration resource name.
public int size()
public void clear()
public java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> iterator()
Iterator
to go through the list of String
key-value pairs in the configuration.
iterator
in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,java.lang.String>>
public void writeXml(java.io.OutputStream out) throws java.io.IOException
OutputStream
.
out
- the output stream to write to.
java.io.IOException
public java.lang.ClassLoader getClassLoader()
ClassLoader
for this job.
public void setClassLoader(java.lang.ClassLoader classLoader)
classLoader
- the new class loader.public java.lang.String toString()
toString
in class java.lang.Object
public void setQuietMode(boolean quietmode)
quietmode
- true
to set quiet-mode on, false
to turn it off.public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public void readFields(java.io.DataInput in) throws java.io.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.
java.io.IOException
public void write(java.io.DataOutput out) throws java.io.IOException
Writable
out
.
write
in interface Writable
out
- DataOuput
to serialize this object into.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |