侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Hadoop学习笔记3:org.apache.hadoop.conf

2022-07-04 星期一 / 0 评论 / 0 点赞 / 65 阅读 / 6337 字

主要讲解org.apache.hadoop.conf包里的3个类的作用。 看完这个,你绝对可以对配置项这一块非常清楚了。 类的个数: 3个1 包: 【org.apache.hadoop.conf

主要讲解org.apache.hadoop.conf包里的3个类的作用。

看完这个,你绝对可以对配置项这一块非常清楚了。

类的个数: 3个1 包: 【org.apache.hadoop.conf】描述:本包与【配置参数配置】相关,包含3个类(接口),Configurable,Configuration,Configured.1.1)	Configurable 【接口】public interface Configurable {函数成员:	void  setConf ( Configuration conf) ;//接口函数,设置Configuration对象Configuration   getConf() ; //接口函数,获取Configuration 对象。}1.2)Configuration 【类】public class Configuration{	变量成员:    private static final Logger LOG =LogFormatter.getLogger("org.apache.hadoop.conf.Configuration");private ArrayList defaultResources = new ArrayList();    private ArrayList finalResources = new ArrayList();    private Properties properties;    private ClassLoader classLoader =     Thread.currentThread().getContextClassLoader();函数成员:public Configuration(){1-	在本地的defaultResources列表中添加"hadoop-default.xml"2-	在本地的finalResources列表中添加"hadoop-site.xml"}public Configuration(Configuration other){1-	本地的defaultResources无条件设置为other相应的defaultResources的复制版本。2-	本地的finalResources无条件设置为other相应的defaultResources的复制版本。3-	只有当other的properties有效时,才把本地的properties设置为other的properties 的复制版本。}public void addDefaultResource(String name){1-	defaultResources列表中添加name2-	设置本地properties为null}public void addDefaultResource(File file){1-	defaultResources里添加file2-	设置本地properties为NULL}public void addFinalResource(String name){1-	finalResources里添加name2-	设置本地properties为NULL}public void addFinalResource(File file){1-		finalResources里添加file2-	设置本地properties为NULL}private synchronized void addResource(ArrayList resources, Object resource){1-	往resources列表里添加resource2-	设置本地properties为NULL}public Object getObject(String name){ 	直接从本地properties中查询name对应的对象Object.通过方法get(name)}public void setObject(String name, Object value){	直接put(name,value)放入properties中。}public Object get(String name, Object defaultValue){	如果properties中存在name对应的object(通过getObject函数),则返回查询结果否则返回参数defaultValue.}public String get(String name){	直接从properties中查询getProperty(name)}public void set(String name, Object value){	直接对properties设置setProperty(name,value.toString());}public String get(String name, String defaultValue){	如果从properties中查询getProperty(name不为空,则返回结果否则返回defaultValue.}public int getInt(String name, int defaultValue){尝试查询name对应的整数,失败则返回defaultValue.}public void setInt(String name, int value){	在本地properties中加入(name,value).}public long getLong(String name, long defaultValue){	尝试获取name对应的long,失败则返回defaultValue.}public void setLong(String name, long value){	 设置(name,value).}public float getFloat(String name, float defaultValue){	尝试获取name对应的float,失败则返回defaultValue.}public boolean getBoolean(String name, boolean defaultValue){	尝试获取name对应的boolean,失败则返回defaultValue.}public void setBoolean(String name, boolean value){	往properties中添加(name,value);}public String[] getStrings(String name){	尝试将name通过", /t/n/r/f"来分割,结果作为数组返回。}public Class getClass(String name, Class defaultValue) {	尝试找到name对应的class,不存在的话则返回defaultValue.}public Class getClass(String propertyName, Class defaultValue,Class xface){	尝试找到propertyName对应的class,没有则赋值为defaultValue.总之,这两者任意一个结果必须满足可以转化为xface类型。}public URL getResource(String name){	通过本地的classLoader找到name对应的URL}public void setClass(String propertyName, Class theClass, Class xface){	在保证theClass可以转化为xface的前提下设置(propertyName,theClass).}private synchronized Properties getProps(){1-	如果本地properties未初始化,则基于defaultResources&finalResources来初始化properties.2-	保证properties初始化后,返回properties.}private void loadResources(Properties props,                             ArrayList resources,                             boolean reverse, boolean quiet){	基于resources里的各个item,来赋值props.}private void loadResource(Properties properties, Object name, boolean quiet){	基于单个name指定的文件,来赋值props.}public InputStream getConfResourceAsInputStream(String name){	尝试做这样的事情1-	name找到对应的URL2-	URL.openStream().}public Reader getConfResourceAsReader(String name){	尝试做这样的事情1-	name找到对应的URL2-	new InputStreamReader(url.openStream()).3-	当然失败了,则返回NULL}private void toString(ArrayList resources, StringBuffer sb){	遍历resources,将内容添加到sb中去1-	文件,直接添加文件内容2-	字符串,那就直接添加字符串吧。}public String toString(){	格式如下:Configuration:+defaults: + defaultResources对应的字符串+final: +finalResources对应的字符串}public void write(OutputStream out) throws IOException{	遍历本地的properties 中的key,value.过滤掉value不为 string类型的配置项。合法的配置项通过out写。}public File getFile(String dirsProp, String path) throws IOException {1-	把dirsProp 分割成若干数组2-	从数组中通过某个算法从某个下标(不一定是0,并且会保证遍历数组一遍)开始遍历数组每一项。3-	当这个数组对应的文件夹存在或者可以被创建时,返回(选中的数组项,path)构成的file.}}1.3)Configured【类】Public class Configured implements Configurable{	private Configuration conf;函数成员如下:public void setConf(Configuration conf){	设置本地conf为参数conf指向的对象的引用}public Configuration getConf(){	返回本地的 conf}public Configured(Configuration conf){	设置本地conf为参数conf指向的对象的引用}}


广告 广告

评论区