org.apache.hadoop.conf

org.apache.hadoop.conf

Configuration of system parameters. html

主要做用爲配置系統參數 java


Interface Summary apache

Configurable api

Something that may be configured with a Configuration. app

Class Summary less

Configuration ide

Provides access to configuration parameters. oop

Configuration.IntegerRanges 測試

A class that represents a set of positive integer ranges. ui

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提供服務,內部提供整數範圍,測試是否包含在範圍中

相關文章
相關標籤/搜索