以下分析基于Hadoop-0.19.2
我们在写job的时候经常会写这么一句
显而易见,这是加载Hadoop的配置。虽然整个过程简单说无非就是读取配置文件,但还是来简单分析一下内部是如何进行处理的。看一下JobConf这个类的继承关系
我们一般调用的就是上面的这个构造函数,由于没有指明父构造器的类型,所以在new JobConf的时候会调用父类的默认构造器。那么下面来看一下Configuration这个类。
暂停……待续
我们在写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");
}
}
暂停……待续