一,hadoop的配置管理
a,hadoop通过独有的Configuration处理配置信息
-
Configuration conf = new Configuration();
-
conf.addResource("core-default.xml");
-
conf.addResource("core-site.xml");
后者会覆盖前者中 未 final标记的相同配置项
b,hadoop属性扩展
如果配置项 dfs.name.dir的值是 ${hadoop.tmp.dir} /dfs/name, hadoop.tmp.dir的值是 /data,
则结果为/data/dfs/name
c,Configuration 成员变量分析
-
-
boolean quietmode;
-
-
ArrayList<Object> resources;
-
-
Set<String> finalParameters;
-
-
boolean loadDefaults ;
-
-
static ArrayList<String> defaultResources ;
-
-
Properties properties ;
-
-
Properties overlay ;
-
-
ClassLoader classLoader ;
-
public URL getResource(String name){
-
return classLoader.getResource(name);
-
}
-
-
boolean quietmode;
-
-
ArrayList<Object> resources;
-
-
Set<String> finalParameters;
-
-
boolean loadDefaults ;
-
-
static ArrayList<String> defaultResources ;
-
-
Properties properties ;
-
-
Properties overlay ;
-
-
ClassLoader classLoader ;
-
-
-
-
-
-
-
public void addResource(String name){
-
addResourceObject(name);
-
}
-
-
private synchronized void addResourceObject(Object resource) {
-
-
resources.add(resource);
-
reloadConfiguration();
-
}
-
-
private synchronized void reloadConfiguration() {
-
properties = null;
-
finalParameters.clear();
-
}
-
-
-
-
private synchronized Properties getProps(){
-
if(properties==null){
-
properties = new Properties();
-
loadResources(properties,resources,quietmode);
-
}
-
-
return properties;
-
}
-
-
private void loadResources(Properties properties,
-
Object name, boolean quietmode) {
-
try{
-
-
DocumentBuilderFactory documentBuilderFactory =
-
DocumentBuilderFactory.newInstance();
-
-
-
documentBuilderFactory.setIgnoringComments(true);
-
-
-
documentBuilderFactory.setNamespaceAware(true);
-
-
try{
-
-
documentBuilderFactory.setXIncludeAware(true);
-
}catch (Exception e) {
-
-
}
-
-
-
DocumentBuilder builder =
-
documentBuilderFactory.newDocumentBuilder();
-
-
Document doc = null;
-
Element root = null;
-
-
-
-
if(name instanceof URL){
-
-
}else if(name instanceof InputStream){
-
-
}else if(name instanceof Element){
-
root = (Element) name;
-
}
-
}catch (Exception e) {
-
-
}
-
-
}
深入理解hadoop(一)----Common的实现----Configuration
原文:http://blog.csdn.net/u013494310/article/details/19480027