//Hadoop在创建配置类的时候,考虑了三种资源:
//
//URL资源(网络资源,指的是一个链接);
//
//CLASSPATH资源(String形式);
//
//Hadoop文件系统中的Path资源(该资源是基于Hadoop的FileSystem的,使用斜线“/”作为分隔符,如果是绝对路径,应该以“/”开始)
public class Configuration implements Iterable<Map.Entry<String,String>>,
Writable {
//LOG是记录日志的对象
private static final Log LOG = LogFactory.getLog(Configuration.class);
//quietmode对应的是配置信息加载过程是否属于默认的模式,如果属于默认的模式下也就是快速模式,则在配置信息加载的过程中的一些信息不会记录在日志中
private boolean quietmode = true;
/**
* List of configuration resources.
* resources是一个对象组,用于存放有关包含配置信息的对象。
*/
private ArrayList<Object> resources = new ArrayList<Object>();
/**
* List of configuration parameters marked <b>final</b>.
* 是所有配置值被声明为final变量的集合
*/
private Set<String> finalParameters = new HashSet<String>();
//是否加载默认配置
private boolean loadDefaults = true;
/**
* Configuration objects
* 用于多有个对象的相关配置的注册对它们进行管理,弱哈希可以自动清除不再正常使用的键对应的条目
*/
private static final WeakHashMap<Configuration,Object> REGISTRY =
new WeakHashMap<Configuration,Object>();
/**
* List of default Resources. Resources are loaded in the order of the list
* entries
* defaultResources用于存储默认的配置资源名或者路径
*/
private static final CopyOnWriteArrayList<String> defaultResources =
new CopyOnWriteArrayList<String>();
/**
* Flag to indicate if the storage of resource which updates a key needs
* to be stored for each key
*/
private boolean storeResource;
/**
* Stores the mapping of key to the resource which modifies or loads
* the key most recently
*/
private HashMap<String, String> updatingResource;
//如果是老版本的hadoop则加载配置文件hadoop-site.xml不是老版本则加载配置文件core-default.xml,core-site.xml
static{
//print deprecation warning if hadoop-site.xml is found in classpath
ClassLoader cL = Thread.currentThread().getContextClassLoader();
if (cL == null) {
cL = Configuration.class.getClassLoader();
}
if(cL.getResource("hadoop-site.xml")!=null) {
LOG.warn("DEPRECATED: hadoop-site.xml found in the classpath. " +
"Usage of hadoop-site.xml is deprecated. Instead use core-site.xml, "
+ "mapred-site.xml and hdfs-site.xml to override properties of " +
"core-default.xml, mapred-default.xml and hdfs-default.xml " +
"respectively");
}
addDefaultResource("core-default.xml");
addDefaultResource("core-site.xml");
}
//properties存储的是Configuration对象中的全部配置信息,类型Properties是Java提供的对KV配置的一个属性集,提高了对KV配置参数的存储和操作方法
private Properties properties;
//overlay则是进行覆盖的属性
private Properties overlay;
//主要是用于配置冲根据配 置的参数构造相应的对象实例时提供上下文环境的类加载器
private ClassLoader classLoader;
{
classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = Configuration.class.getClassLoader();
}
}