org.apache.hadoop.conf

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()
          Return the configuration used by this object.

 void

setConf(Configuration conf)
          Set the configuration to be used by this object.

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默认指定两个资源文件,加载时按照环境变量设置的顺序。

  1. core-default.xml : Read-only defaults for hadoop.
  2. 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 Parameters

Configuration 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 Expansion

Value strings are first processed for variable expansion. The available properties are:

值字符串第一次为可扩展变量,有效属性为

  1. Other properties defined in this Configuration; and, if a name is undefined here,
  2. 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
          A class that represents a set of positive integer ranges.

Constructor Summary

Configuration()
          A new configuration.


Configuration(boolean loadDefaults)
          A new configuration where the behavior of reading from the default resources can be turned off.


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


Method Summary

static void

addDefaultResource(String name)
          Add a default resource.

 void

addResource(InputStream in)
          Add a configuration resource.

 void

addResource(Path file)
          Add a configuration resource.

 void

addResource(String name)
          Add a configuration resource.

 void

addResource(URL url)
          Add a configuration resource.

 void

clear()
          Clears all keys from the configuration.

String

get(String name)
          Get the value of thenameproperty,nullif no such property exists.

String

get(String name, String defaultValue)
          Get the value of thenameproperty.

 boolean

getBoolean(String name, boolean defaultValue)
          Get the value of thenameproperty as aboolean.

Class<?>

getClass(String name, Class<?> defaultValue)
          Get the value of thenameproperty as aClass.

<U> Class<? extends U>

getClass(String name, Class<? extends U> defaultValue, Class<U> xface)
          Get the value of thenameproperty as aClassimplementing the interface specified byxface.

Class<?>

getClassByName(String name)
          Load a class by name.

Class<?>[]

getClasses(String name, Class<?>... defaultValue)
          Get the value of thenameproperty as an array ofClass.

ClassLoader

getClassLoader()
          Get the ClassLoader for this job.

InputStream

getConfResourceAsInputStream(String name)
          Get an input stream attached to the configuration resource with the givenname.

Reader

getConfResourceAsReader(String name)
          Get a Reader attached to the configuration resource with the givenname.

File

getFile(String dirsProp, String path)
          Get a local file name under a directory named in dirsProp with the given path.

 float

getFloat(String name, float defaultValue)
          Get the value of thenameproperty as afloat.

 int

getInt(String name, int defaultValue)
          Get the value of thenameproperty as anint.

Path

getLocalPath(String dirsProp, String path)
          Get a local file under a directory named by dirsProp with the given path.

 long

getLong(String name, long defaultValue)
          Get the value of thenameproperty as along.

Configuration.IntegerRanges

getRange(String name, String defaultValue)
          Parse the given attribute as a set of integer ranges

String

getRaw(String name)
          Get the value of thenameproperty, without doing variable expansion.

URL

getResource(String name)
          Get the URL for the named resource.

Collection<String>

getStringCollection(String name)
          Get the comma delimited values of thenameproperty as a collection ofStrings.

String[]

getStrings(String name)
          Get the comma delimited values of thenameproperty as an array ofStrings.

String[]

getStrings(String name, String... defaultValue)
          Get the comma delimited values of thenameproperty as an array ofStrings.

Iterator<Map.Entry<String,String>>

iterator()
          Get an Iterator to go through the list ofStringkey-value pairs in the configuration.

static void

main(String[] args)
          For debugging.

 void

readFields(DataInput in)
          Deserialize the fields of this object fromin.

 void

reloadConfiguration()
          Reload configuration from previously added resources.

 void

set(String name, String value)
          Set thevalueof thenameproperty.

 void

setBoolean(String name, boolean value)
          Set the value of thenameproperty to aboolean.

 void

setBooleanIfUnset(String name, boolean value)
          Set the given property, if it is currently unset.

 void

setClass(String name, Class<?> theClass, Class<?> xface)
          Set the value of thenameproperty to the name of atheClassimplementing the given interfacexface.

 void

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

 void

setFloat(String name, float value)
          Set the value of thenameproperty to afloat.

 void

setIfUnset(String name, String value)
          Sets a property if it is currently unset.

 void

setInt(String name, int value)
          Set the value of thenameproperty to anint.

 void

setLong(String name, long value)
          Set the value of thenameproperty to along.

 void

setQuietMode(boolean quietmode)
          Set the quietness-mode.

 void

setStrings(String name, String... values)
          Set the array of string values for thenameproperty as as comma delimited values.

 int

size()
          Return the number of keys in the configuration.

String

toString()

 void

write(DataOutput out)
          Serialize the fields of this object toout.

 void

writeXml(OutputStream out)
          Write out the non-default properties in this configuration to the give OutputStream.

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()
          Construct a Configured.


Configured(Configuration conf)
          Construct a Configured.


Method Summary

Configuration

getConf()
          Return the configuration used by this object.

 void

setConf(Configuration conf)
          Set the configuration to be used by this object.

同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)
          Is the given value in the set of ranges

String

toString()

体会。

Configurable:实现这个接口的类,成为可配置的,可以读取配置文件,进行控制

可以这样理解你想指定,参数,指定配置,应该让它实现Configurable接口

Configuration:此类具体读取和设置配置信息、

读取和配置文件的具体操作类,当从哪个xml文件读取和设置时应该用到它。

xml文件中没有保存类型(type)信息,即属性再被读取的时候,可以被解释为指定的类型。

Configuration.IntegerRanges:为内部类,定义了整数范围。

为Configuration提供服务,内部提供整数范围,测试是否包含在范围中

转载于:https://my.oschina.net/u/941279/blog/108571

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值