Save This Page
Home » hadoop-0.14.4 » org.apache » hadoop » conf » [javadoc | source]
org.apache.hadoop.conf
public class: Configuration [javadoc | source]
java.lang.Object
   org.apache.hadoop.conf.Configuration

All Implemented Interfaces:
    Iterable

Direct Known Subclasses:
    JobConf, HBaseConfiguration

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:
 public Configuration() 
 public Configuration(Configuration other) 
    A new configuration with the same settings cloned from another.
Method from org.apache.hadoop.conf.Configuration Summary:
addDefaultResource,   addDefaultResource,   addDefaultResource,   addFinalResource,   addFinalResource,   addFinalResource,   entries,   get,   get,   get,   getBoolean,   getClass,   getClass,   getClassByName,   getClassLoader,   getConfResourceAsInputStream,   getConfResourceAsReader,   getFile,   getFloat,   getInt,   getLocalPath,   getLong,   getObject,   getRaw,   getResource,   getStrings,   iterator,   main,   set,   set,   setBoolean,   setClass,   setClassLoader,   setInt,   setLong,   setObject,   setQuietMode,   toString,   write
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.hadoop.conf.Configuration Detail:
 public  void addDefaultResource(String name) 
    Add a default resource.
 public  void addDefaultResource(URL url) 
    Add a default resource.
 public  void addDefaultResource(Path file) 
    Add a default resource.
 public  void addFinalResource(String name) 
    Add a final resource.
 public  void addFinalResource(URL url) 
    Add a final resource.
 public  void addFinalResource(Path file) 
    Add a final resource.
 public Iterator entries() 
Deprecated! use - iterator() instead

 public String get(String name) 
    Returns the value of the name property, or null if no such property exists.
 public Object get(String name,
    Object defaultValue) 
Deprecated! A - side map of Configuration to Object should be used instead.

    Returns the value of the name property. If no such property exists, then defaultValue is returned.
 public String get(String name,
    String defaultValue) 
    Returns the value of the name property. If no such property exists, then defaultValue is returned.
 public boolean getBoolean(String name,
    boolean defaultValue) 
    Returns the value of the 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 Class getClass(String name,
    Class defaultValue) 
    Returns the value of the name property as a Class. If no such property is specified, then defaultValue is returned.
 public Class getClass(String propertyName,
    Class defaultValue,
    Class xface) 
    Returns the value of the 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 Class getClassByName(String name) throws ClassNotFoundException 
    Load a class by name.
 public ClassLoader getClassLoader() 
    Get the class loader for this job.
 public InputStream getConfResourceAsInputStream(String name) 
    Returns an input stream attached to the configuration resource with the given name.
 public Reader getConfResourceAsReader(String name) 
    Returns a reader attached to the configuration resource with the given name.
 public File getFile(String dirsProp,
    String path) throws IOException 
    Returns a local file name under a directory named in dirsProp with the given path. If dirsProp contains multiple directories, then one is chosen based on path's hash code. If the selected directory does not exist, an attempt is made to create it.
 public float getFloat(String name,
    float defaultValue) 
    Returns the value of the 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 int getInt(String name,
    int defaultValue) 
    Returns the value of the 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 Path getLocalPath(String dirsProp,
    String path) throws IOException 
    Returns a local file under a directory named in dirsProp with the given path. If dirsProp contains multiple directories, then one is chosen based on path's hash code. If the selected directory does not exist, an attempt is made to create it.
 public long getLong(String name,
    long defaultValue) 
    Returns the value of the 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 Object getObject(String name) 
Deprecated! A - side map of Configuration to Object should be used instead.

    Returns the value of the name property, or null if no such property exists.
 public String getRaw(String name) 
    Get the value of the name property, without doing variable expansion.
 public URL getResource(String name) 
    Returns the URL for the named resource.
 public String[] getStrings(String name) 
    Returns the value of the name property as an array of strings. If no such property is specified, then null is returned. Values are comma delimited.
 public Iterator iterator() 
    Go through the list of String key-value pairs in the configuration.
 public static  void main(String[] args) throws Exception 
    For debugging. List non-default properties to the terminal and exit.
 public  void set(String name,
    Object value) 
Deprecated!
    Sets the value of the name property.
 public  void set(String name,
    String value) 
    Sets the value of the name property.
 public  void setBoolean(String name,
    boolean value) 
    Sets the value of the name property to an integer.
 public  void setClass(String propertyName,
    Class theClass,
    Class xface) 
    Sets the value of the name property to the name of a class. First checks that the class implements the named interface.
 public  void setClassLoader(ClassLoader classLoader) 
    Set the class loader that will be used to load the various objects.
 public  void setInt(String name,
    int value) 
    Sets the value of the name property to an integer.
 public  void setLong(String name,
    long value) 
    Sets the value of the name property to a long.
 public  void setObject(String name,
    Object value) 
Deprecated!
    Sets the value of the name property.
 public synchronized  void setQuietMode(boolean value) 
    Make this class quiet. Error and informational messages might not be logged.
 public String toString() 
 public  void write(OutputStream out) throws IOException 
    Writes non-default properties in this configuration.