com.nhncorp.neptune.common.conf
Class NConfiguration

java.lang.Object
  extended by com.nhncorp.neptune.common.conf.NConfiguration

public class NConfiguration
extends java.lang.Object

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.


Field Summary
static java.lang.String SERVICE_NAME
           
static java.lang.String USER_ID_KEY
           
static java.lang.String USER_PASSWD_KEY
           
 
Constructor Summary
NConfiguration()
          A new configuration.
NConfiguration(org.apache.hadoop.mapred.JobConf jobConf)
           
NConfiguration(NConfiguration other)
          A new configuration with the same settings cloned from another.
 
Method Summary
 void addDefaultResource(java.lang.String name)
          Add a default resource.
 void addDefaultResource(java.net.URL url)
          Add a default resource.
 void addFinalResource(java.lang.String name)
          Add a final resource.
 void addFinalResource(java.net.URL url)
          Add a final resource.
 java.util.Iterator entries()
           
 java.lang.String get(java.lang.String name)
          Returns the value of the name property, or null if no such property exists.
 java.lang.String get(java.lang.String name, java.lang.String defaultValue)
          Returns the value of the name property.
 boolean getBoolean(java.lang.String name, boolean defaultValue)
          Returns the value of the name property as an boolean.
 java.lang.Class<?> getClass(java.lang.String name, java.lang.Class<?> defaultValue)
          Returns the value of the name property as a Class.
<U> java.lang.Class<? extends U>
getClass(java.lang.String propertyName, java.lang.Class<? extends U> defaultValue, java.lang.Class<U> xface)
          Returns the value of the name property as a Class.
 java.lang.Class<?> getClassByName(java.lang.String name)
          Load a class by name.
 java.lang.ClassLoader getClassLoader()
          Get the class loader for this job.
 java.io.InputStream getConfResourceAsInputStream(java.lang.String name)
          Returns an input stream attached to the configuration resource with the given name.
 java.io.Reader getConfResourceAsReader(java.lang.String name)
          Returns a reader attached to the configuration resource with the given name.
 java.io.File getFile(java.lang.String dirsProp, java.lang.String path)
          Returns a local file name under a directory named in dirsProp with the given path.
 float getFloat(java.lang.String name, float defaultValue)
          Returns the value of the name property as a float.
 int getInt(java.lang.String name, int defaultValue)
          Returns the value of the name property as an integer.
 long getLong(java.lang.String name, long defaultValue)
          Returns the value of the name property as a long.
 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)
          Returns the URL for the named resource.
 java.lang.String[] getStrings(java.lang.String name)
          Returns the value of the name property as an array of strings.
 java.lang.String getUserId()
           
static void main(java.lang.String[] args)
          For debugging.
 void set(java.lang.String name, java.lang.Object value)
          Sets the value of the name property.
 void setBoolean(java.lang.String name, boolean value)
          Sets the value of the name property to an integer.
 void setClass(java.lang.String propertyName, java.lang.Class<?> theClass, java.lang.Class<?> xface)
          Sets the value of the name property to the name of a class.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the class loader that will be used to load the various objects.
 void setInt(java.lang.String name, int value)
          Sets the value of the name property to an integer.
 void setJobConf(org.apache.hadoop.mapred.JobConf jobConf)
           
 void setLong(java.lang.String name, long value)
          Sets the value of the name property to a long.
 void setQuietMode(boolean value)
          Make this class quiet.
 void setUserId(java.lang.String id)
           
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes non-default properties in this configuration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

USER_ID_KEY

public static java.lang.String USER_ID_KEY

USER_PASSWD_KEY

public static java.lang.String USER_PASSWD_KEY

SERVICE_NAME

public static java.lang.String SERVICE_NAME
Constructor Detail

NConfiguration

public NConfiguration()
A new configuration.


NConfiguration

public NConfiguration(NConfiguration other)
A new configuration with the same settings cloned from another.


NConfiguration

public NConfiguration(org.apache.hadoop.mapred.JobConf jobConf)
Method Detail

setJobConf

public void setJobConf(org.apache.hadoop.mapred.JobConf jobConf)

addDefaultResource

public void addDefaultResource(java.lang.String name)
Add a default resource.


addDefaultResource

public void addDefaultResource(java.net.URL url)
Add a default resource.


addFinalResource

public void addFinalResource(java.lang.String name)
Add a final resource.


addFinalResource

public void addFinalResource(java.net.URL url)
Add a final resource.


get

public java.lang.String get(java.lang.String name)
Returns the value of the name property, or null if no such property exists.


getRaw

public java.lang.String getRaw(java.lang.String name)
Get the value of the name property, without doing variable expansion.

Parameters:
name - the property name
Returns:
the result or null if no such property exists

set

public void set(java.lang.String name,
                java.lang.Object value)
Sets the value of the name property.


get

public java.lang.String get(java.lang.String name,
                            java.lang.String defaultValue)
Returns the value of the name property. If no such property exists, then defaultValue is returned.


getInt

public int getInt(java.lang.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.


setInt

public void setInt(java.lang.String name,
                   int value)
Sets the value of the name property to an integer.


getLong

public long getLong(java.lang.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.


setLong

public void setLong(java.lang.String name,
                    long value)
Sets the value of the name property to a long.


getFloat

public float getFloat(java.lang.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.


getBoolean

public boolean getBoolean(java.lang.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".


setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
Sets the value of the name property to an integer.


getStrings

public java.lang.String[] getStrings(java.lang.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.


getClassByName

public java.lang.Class<?> getClassByName(java.lang.String name)
                                  throws java.lang.ClassNotFoundException
Load a class by name.

Parameters:
name - the class name
Returns:
the class object
Throws:
java.lang.ClassNotFoundException - if the class is not found

getClass

public java.lang.Class<?> getClass(java.lang.String name,
                                   java.lang.Class<?> defaultValue)
Returns the value of the name property as a Class. If no such property is specified, then defaultValue is returned.


getClass

public <U> java.lang.Class<? extends U> getClass(java.lang.String propertyName,
                                                 java.lang.Class<? extends U> defaultValue,
                                                 java.lang.Class<U> 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.


setClass

public void setClass(java.lang.String propertyName,
                     java.lang.Class<?> theClass,
                     java.lang.Class<?> xface)
Sets the value of the name property to the name of a class. First checks that the class implements the named interface.


getFile

public java.io.File getFile(java.lang.String dirsProp,
                            java.lang.String path)
                     throws java.io.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.

Throws:
java.io.IOException

getResource

public java.net.URL getResource(java.lang.String name)
Returns the URL for the named resource.


getConfResourceAsInputStream

public java.io.InputStream getConfResourceAsInputStream(java.lang.String name)
Returns an input stream attached to the configuration resource with the given name.


getConfResourceAsReader

public java.io.Reader getConfResourceAsReader(java.lang.String name)
Returns a reader attached to the configuration resource with the given name.


entries

public java.util.Iterator entries()
Returns:
Iterator< Map.Entry<String,String> >

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Writes non-default properties in this configuration.

Throws:
java.io.IOException

getClassLoader

public java.lang.ClassLoader getClassLoader()
Get the class loader for this job.

Returns:
the correct class loader

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader that will be used to load the various objects.

Parameters:
classLoader - the new class loader

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setQuietMode

public void setQuietMode(boolean value)
Make this class quiet. Error and informational messages might not be logged.


setUserId

public void setUserId(java.lang.String id)

getUserId

public java.lang.String getUserId()

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
For debugging. List non-default properties to the terminal and exit.

Throws:
java.lang.Exception