|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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.
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 a File, then the local filesystem is examined directly, without referring to the CLASSPATH.
Configuration resources are of two types: default and final. Default values are loaded first and final values are loaded last, and thus override default values.
Hadoop's default resource is the String "hadoop-default.xml" and its final resource is the String "hadoop-site.xml". Other tools built on Hadoop may specify additional resources.
The values returned by most get* methods are based on String representations. This String is processed for variable expansion. The available variables are the System properties and the other properties defined in this Configuration.
The only get* method that is not processed for variable expansion is
getObject(String)
(as it cannot assume that the returned values are String).
You can use getObject to obtain the raw value of a String property without
variable expansion: if (String)conf.getObject("my.jdk") is "JDK ${java.version}"
then conf.get("my.jdk") is "JDK 1.5.0"
Example XML config using variables:
<name>basedir</name><value>/user/${user.name}</value>
<name>tempdir</name><value>${basedir}/tmp</value>
When conf.get("tempdir") is called:
${basedir} is resolved to another property in this Configuration.
Then ${user.name} is resolved to a System property.
Constructor Summary | |
---|---|
Configuration()
A new configuration. |
|
Configuration(Configuration other)
A new configuration with the same settings cloned from another. |
|
Configuration(File confDir)
|
|
Configuration(List<File> confDirs)
|
Method Summary | |
---|---|
void |
addDefaultResource(Path file)
Add a default resource. |
void |
addDefaultResource(String name)
Add a default resource. |
void |
addDefaultResource(URL url)
Add a default resource. |
void |
addFinalResource(Path file)
Add a final resource. |
void |
addFinalResource(String name)
Add a final resource. |
void |
addFinalResource(URL url)
Add a final resource. |
Iterator |
entries()
|
String |
get(String name)
Returns the value of the name property, or null if no
such property exists. |
Object |
get(String name,
Object defaultValue)
Returns the value of the name property. |
String |
get(String name,
String defaultValue)
Returns the value of the name property. |
boolean |
getBoolean(String name,
boolean defaultValue)
Returns the value of the name property as an boolean. |
Class |
getClass(String name,
Class defaultValue)
Returns the value of the name property as a Class. |
Class |
getClass(String propertyName,
Class defaultValue,
Class xface)
Returns the value of the name property as a Class. |
Class |
getClassByName(String name)
Load a class by name. |
ClassLoader |
getClassLoader()
Get the class loader for this job. |
InputStream |
getConfResourceAsInputStream(String name)
Returns an input stream attached to the configuration resource with the given name . |
Reader |
getConfResourceAsReader(String name)
Returns a reader attached to the configuration resource with the given name . |
File |
getFile(String dirsProp,
String path)
Returns a local file name under a directory named in dirsProp with the given path. |
float |
getFloat(String name,
float defaultValue)
Returns the value of the name property as a float. |
int |
getInt(String name,
int defaultValue)
Returns the value of the name property as an integer. |
Path |
getLocalPath(String dirsProp,
String path)
Returns a local file under a directory named in dirsProp with the given path. |
long |
getLong(String name,
long defaultValue)
Returns the value of the name property as a long. |
Object |
getObject(String name)
Returns the value of the name property, or null if no such
property exists. |
URL |
getResource(String name)
Returns the URL for the named resource. |
String[] |
getStrings(String name)
Returns the value of the name property as an array of
strings. |
List<Object> |
listDefaultAndFinalResources()
|
static void |
main(String[] args)
For debugging. |
void |
set(String name,
Object value)
Sets the value of the name property. |
void |
setBoolean(String name,
boolean value)
Sets the value of the name property to an integer. |
void |
setClass(String propertyName,
Class theClass,
Class xface)
Sets the value of the name property to the name of a class. |
void |
setClassLoader(ClassLoader classLoader)
Set the class loader that will be used to load the various objects. |
void |
setInt(String name,
int value)
Sets the value of the name property to an integer. |
void |
setLong(String name,
long value)
Sets the value of the name property to a long. |
void |
setObject(String name,
Object value)
Sets the value of the name property. |
void |
setQuietMode(boolean value)
Make this class quiet. |
String |
toString()
|
void |
write(OutputStream out)
Writes non-default properties in this configuration. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Configuration()
public Configuration(File confDir)
public Configuration(List<File> confDirs)
public Configuration(Configuration other)
Method Detail |
---|
public void addDefaultResource(String name)
public void addDefaultResource(URL url)
public void addDefaultResource(Path file)
public void addFinalResource(String name)
public void addFinalResource(URL url)
public void addFinalResource(Path file)
public Object getObject(String name)
name
property, or null if no such
property exists.
public void setObject(String name, Object value)
name
property.
public Object get(String name, Object defaultValue)
name
property. If no such property
exists, then defaultValue
is returned.
public String get(String name)
name
property, or null if no
such property exists.
public void set(String name, Object value)
name
property.
public String get(String name, String defaultValue)
name
property. If no such property
exists, then defaultValue
is returned.
public int getInt(String name, int defaultValue)
name
property as an integer. If no
such property is specified, or if the specified value is not a valid
integer, then defaultValue
is returned.
public void setInt(String name, int value)
name
property to an integer.
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.
public void setLong(String name, long value)
name
property to a long.
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.
public boolean getBoolean(String name, boolean defaultValue)
name
property as an boolean. If no
such property is specified, or if the specified value is not a valid
boolean, then defaultValue
is returned. Valid boolean values
are "true" and "false".
public void setBoolean(String name, boolean value)
name
property to an integer.
public String[] getStrings(String name)
name
property as an array of
strings. If no such property is specified, then null
is returned. Values are comma delimited.
public Class getClassByName(String name) throws ClassNotFoundException
name
- the class name
ClassNotFoundException
- if the class is not foundpublic Class getClass(String name, Class defaultValue)
name
property as a Class. If no
such property is specified, then defaultValue
is returned.
public Class getClass(String propertyName, Class defaultValue, Class xface)
name
property as a Class. If no
such property is specified, then defaultValue
is returned.
An error is thrown if the returned class does not implement the named
interface.
public void setClass(String propertyName, Class theClass, Class xface)
name
property to the name of a class.
First checks that the class implements the named interface.
public Path getLocalPath(String dirsProp, String path) throws IOException
IOException
public File getFile(String dirsProp, String path) throws IOException
IOException
public URL getResource(String name)
public InputStream getConfResourceAsInputStream(String name)
name
.
public Reader getConfResourceAsReader(String name)
name
.
public Iterator entries()
public void write(OutputStream out) throws IOException
IOException
public ClassLoader getClassLoader()
public void setClassLoader(ClassLoader classLoader)
classLoader
- the new class loaderpublic String toString()
toString
in class Object
public void setQuietMode(boolean value)
public List<Object> listDefaultAndFinalResources()
public static void main(String[] args) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |