org.apache.hadoop.conf
Configuration of system parameters.
主要作用为配置系统参数
Interface Summary | |
Configurable | Something that may be configured with a Configuration. |
Class Summary | |
Configuration | Provides access to configuration parameters. |
Configuration.IntegerRanges | A class that represents a set of positive integer ranges. |
Configured | Base class for things that may be configured with a Configuration. |
org.apache.hadoop.conf
Interface Configurable
All Known Subinterfaces:
SequenceFileInputFilter.Filter, Tool
All Known Implementing Classes:
。。。。
public interface Configurable
Something that may be configured with a Configuration.
Method Summary | |
Configuration | getConf() |
void | setConf(Configuration conf) |
org.apache.hadoop.conf
Class Configuration
java.lang.Object
org.apache.hadoop.conf.Configuration
All Implemented Interfaces:
Iterable<Map.Entry<String,String>>, Writable
Direct Known Subclasses:
JobConf
public class Configuration
extends Object
implements Iterable<Map.Entry<String,String>>, Writable
Provides access to configuration parameters.
提供访问配置参数
Resources(资源)Configurations are specified by resources. A resource contains a set of name/value pairs as XML data. Each resource is named by either aStringor by a Path. If named by aString, then the classpath is examined for a file with that name. If named by aPath, then the local filesystem is examined directly, without referring to the classpath.
Configuration需要指定资源,资源文件包含一系列键值对在xml文件中。每个资源文件名称为字符串或路径。如果为字符串,设置环境变量中查找文件名称。如果名称为路径,直接检测本地文件系统,不参考环境变量
Unless explicitly turned off, Hadoop by default specifies two resources, loaded in-order from the classpath:
除非设置关闭,hadoop默认指定两个资源文件,加载时按照环境变量设置的顺序。
- core-default.xml : Read-only defaults for hadoop.
- core-site.xml: Site-specific configuration for a given hadoop installation.
Applications may add additional resources, which are loaded subsequent to these resources in the order they are added.
应用程序可以加载自己的资源文件,加载时按照资源文件添加顺序
Final ParametersConfiguration 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:
Configuration参数可以声明为final,一旦一个资源文件的value值声明为final,后来加载的资源文件无法改变其值(默认后来加载的资源文件会覆盖相同的之前加载文件的属性),例如下面例子
<property>
<name>dfs.client.buffer.dir</name>
<value>/tmp/hadoop/dfs/client</value>
<final>true</final>
</property>
Administrators typically define parameters as final incore-site.xmlfor values that user applications may not alter.
管理员可以定义参数final在core-site.xml中值,应用程序无法改变它
Variable ExpansionValue strings are first processed for variable expansion. The available properties are:
值字符串第一次为可扩展变量,有效属性为
- Other properties defined in this Configuration; and, if a name is undefined here,
- Properties in System.getProperties().
其他属性定义在这个配置中,而且名称没有在这里定义
属性通过System.getProerties()设定
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>
Whenconf.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.
当调用conf.get(“tempdir”),这是${basedir}将会解析为另一个属性对于本次配置,然而${user.name}常常被根据名字系统设置的值
Nested Class Summary | |
static class | Configuration.IntegerRanges |
Constructor Summary | |
Configuration() | |
Configuration(boolean loadDefaults) | |
Configuration(Configuration other) | |
Method Summary | ||
static void | addDefaultResource(String name) | |
void | addResource(InputStream in) | |
void | addResource(Path file) | |
void | addResource(String name) | |
void | addResource(URL url) | |
void | clear() | |
get(String name) | ||
get(String name, String defaultValue) | ||
boolean | getBoolean(String name, boolean defaultValue) | |
Class<?> | getClass(String name, Class<?> defaultValue) | |
| getClass(String name, Class<? extends U> defaultValue, Class<U> xface) | |
Class<?> | getClassByName(String name) | |
Class<?>[] | getClasses(String name, Class<?>... defaultValue) | |
getClassLoader() | ||
getConfResourceAsInputStream(String name) | ||
getConfResourceAsReader(String name) | ||
getFile(String dirsProp, String path) | ||
float | getFloat(String name, float defaultValue) | |
int | getInt(String name, int defaultValue) | |
Path | getLocalPath(String dirsProp, String path) | |
long | getLong(String name, long defaultValue) | |
Configuration.IntegerRanges | getRange(String name, String defaultValue) | |
getRaw(String name) | ||
getResource(String name) | ||
getStringCollection(String name) | ||
String[] | getStrings(String name) | |
String[] | getStrings(String name, String... defaultValue) | |
iterator() | ||
static void | main(String[] args) | |
void | readFields(DataInput in) | |
void | reloadConfiguration() | |
void | set(String name, String value) | |
void | setBoolean(String name, boolean value) | |
void | setBooleanIfUnset(String name, boolean value) | |
void | setClass(String name, Class<?> theClass, Class<?> xface) | |
void | setClassLoader(ClassLoader classLoader) | |
void | setFloat(String name, float value) | |
void | setIfUnset(String name, String value) | |
void | setInt(String name, int value) | |
void | setLong(String name, long value) | |
void | setQuietMode(boolean quietmode) | |
void | setStrings(String name, String... values) | |
int | size() | |
toString() | ||
void | write(DataOutput out) | |
void | writeXml(OutputStream out) |
org.apache.hadoop.conf
Class Configured
java.lang.Object
org.apache.hadoop.conf.Configured
All Implemented Interfaces:
Configurable
Direct Known Subclasses:
。。。。
public class Configured
extends Object
implements Configurable
Base class for things that may be configured with a Configuration.
Constructor Summary | |
Configured() | |
Configured(Configuration conf) | |
Method Summary | |
Configuration | getConf() |
void | setConf(Configuration conf) |
同Configurable很相似是Configurable的实现类。了解不多
org.apache.hadoop.conf
Class Configuration.IntegerRanges
java.lang.Object
org.apache.hadoop.conf.Configuration.IntegerRanges
Enclosing class:(就是为下面类的内部类,也即嵌套类)
Configuration
public static class Configuration.IntegerRanges
extends Object
A class that represents a set of positive integer ranges. It parses strings of the form: "2-3,5,7-" where ranges are separated by comma and the lower/upper bounds are separated by dash. Either the lower or upper bound may be omitted meaning all values up to or over. So the string above means 2, 3, 5, and 7, 8, 9, ...
一个类表示了一系列确定的整数范围,它解析字符串表单“2-3,5,7-”逗号分隔范围,边界用-分隔。如果其中一个边界省略没有写那么代表没有限制。上面例子解析为
2, 3, 5, and 7, 8, 9, ..
Constructor Summary | |
Configuration.IntegerRanges() | |
Configuration.IntegerRanges(String newValue) | |
Method Summary | |
boolean | isIncluded(int value) |
toString() |
体会。
Configurable:实现这个接口的类,成为可配置的,可以读取配置文件,进行控制
可以这样理解你想指定,参数,指定配置,应该让它实现Configurable接口
Configuration:此类具体读取和设置配置信息、
读取和配置文件的具体操作类,当从哪个xml文件读取和设置时应该用到它。
xml文件中没有保存类型(type)信息,即属性再被读取的时候,可以被解释为指定的类型。
Configuration.IntegerRanges:为内部类,定义了整数范围。
为Configuration提供服务,内部提供整数范围,测试是否包含在范围中