|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.nhncorp.neptune.common.conf.NConfiguration
public class NConfiguration
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. |
|
|
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 |
|---|
public static java.lang.String USER_ID_KEY
public static java.lang.String USER_PASSWD_KEY
public static java.lang.String SERVICE_NAME
| Constructor Detail |
|---|
public NConfiguration()
public NConfiguration(NConfiguration other)
public NConfiguration(org.apache.hadoop.mapred.JobConf jobConf)
| Method Detail |
|---|
public void setJobConf(org.apache.hadoop.mapred.JobConf jobConf)
public void addDefaultResource(java.lang.String name)
public void addDefaultResource(java.net.URL url)
public void addFinalResource(java.lang.String name)
public void addFinalResource(java.net.URL url)
public java.lang.String get(java.lang.String 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
public void set(java.lang.String name,
java.lang.Object value)
name property.
public java.lang.String get(java.lang.String name,
java.lang.String defaultValue)
name property. If no such property
exists, then defaultValue is returned.
public int getInt(java.lang.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(java.lang.String name,
int value)
name property to an integer.
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.
public void setLong(java.lang.String name,
long value)
name property to a long.
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.
public boolean getBoolean(java.lang.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(java.lang.String name,
boolean value)
name property to an integer.
public java.lang.String[] getStrings(java.lang.String name)
name property as an array of
strings. If no such property is specified, then null
is returned. Values are comma delimited.
public 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<?> getClass(java.lang.String name,
java.lang.Class<?> defaultValue)
name property as a Class. If no
such property is specified, then defaultValue is returned.
public <U> java.lang.Class<? extends U> getClass(java.lang.String propertyName,
java.lang.Class<? extends U> defaultValue,
java.lang.Class<U> 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(java.lang.String propertyName,
java.lang.Class<?> theClass,
java.lang.Class<?> xface)
name property to the name of a class.
First checks that the class implements the named interface.
public java.io.File getFile(java.lang.String dirsProp,
java.lang.String path)
throws java.io.IOException
java.io.IOExceptionpublic java.net.URL getResource(java.lang.String name)
public java.io.InputStream getConfResourceAsInputStream(java.lang.String name)
name.
public java.io.Reader getConfResourceAsReader(java.lang.String name)
name.
public java.util.Iterator entries()
public void write(java.io.OutputStream out)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.ClassLoader getClassLoader()
public void setClassLoader(java.lang.ClassLoader classLoader)
classLoader - the new class loaderpublic java.lang.String toString()
toString in class java.lang.Objectpublic void setQuietMode(boolean value)
public void setUserId(java.lang.String id)
public java.lang.String getUserId()
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||