Configuration简析

以下分析基于Hadoop-0.19.2

我们在写job的时候经常会写这么一句
JobConf conf = new JobConf(***.class)

显而易见,这是加载Hadoop的配置。虽然整个过程简单说无非就是读取配置文件,但还是来简单分析一下内部是如何进行处理的。看一下JobConf这个类的继承关系
public class JobConf extends Configuration {
public JobConf(Class exampleClass) {
setJarByClass(exampleClass);
}
………
}

我们一般调用的就是上面的这个构造函数,由于没有指明父构造器的类型,所以在new JobConf的时候会调用父类的默认构造器。那么下面来看一下Configuration这个类。
public class Configuration implements Iterable<Map.Entry<String,String>>, Writable {
private static final Log LOG = LogFactory.getLog(Configuration.class);

//从参数名
private boolean quietmode = true;

//配置列表
private ArrayList<Object> resources = new ArrayList<Object>();

//最终配置列表
private Set<String> finalParameters = new HashSet<String>();

//
private Properties properties;
private Properties overlay;
private ClassLoader classLoader;
{
classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = Configuration.class.getClassLoader();
}
}

/** A new configuration. */
public Configuration() {
this(true);
}

/** A new configuration where the behavior of reading from the default
* resources can be turned off.
*
* If the parameter {@code loadDefaults} is false, the new instance
* will not load resources from the default files.
* @param loadDefaults specifies whether to load from the default files
*/
public Configuration(boolean loadDefaults) {
if (LOG.isDebugEnabled()) {
LOG.debug(StringUtils.stringifyException(new IOException("config()")));
}
if (loadDefaults) {
resources.add("hadoop-default.xml");
resources.add("hadoop-site.xml");
}
}


暂停……待续
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值