日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

【Nutch2.2.1源代码分析之4】Nutch加载配置文件的方法

發(fā)布時(shí)間:2024/1/23 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Nutch2.2.1源代码分析之4】Nutch加载配置文件的方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

小結(jié):

(1)在nutch中,一般通過(guò)ToolRunner來(lái)運(yùn)行hadoop job,此方法可以方便的通過(guò)ToolRunner.run(Configuration conf,Tool tool,String[] args)來(lái)加載配置文件。
(2)conf參數(shù)會(huì)通過(guò)NutchConfiguration.creat()方法創(chuàng)建,此方法先加載hadoop的core-default.xml與core-site.xml,然后再加載nutch-default.xml與nutch-site.xml。



1、NutchConfiguration.java用于加載及獲取Nutch的相關(guān)參數(shù)。 Utility to create Hadoop Configurations that include Nutch-specific ?resources.? 即它會(huì)加載hadoop及nutch中的參數(shù)文件。 關(guān)鍵是2個(gè)create()方法,它加載了參數(shù)文件的同時(shí),又返回了Configuration對(duì)象。
2、不帶參數(shù)的create方法 public static Configuration create() {Configuration conf = new Configuration();setUUID(conf);addNutchResources(conf);return conf;} 首先,new Configuration()時(shí),默認(rèn)會(huì)加載core-default.xml與core-site.xml。 然后增加UUID這個(gè)參數(shù)。 最后增加nutch相關(guān)的參數(shù): private static Configuration addNutchResources(Configuration conf) {conf.addResource("nutch-default.xml");conf.addResource("nutch-site.xml");return conf;} 關(guān)于Configuraion,請(qǐng)參見(jiàn):http://blog.csdn.net/jediael_lu/article/details/38751885 關(guān)于UUID,請(qǐng)參見(jiàn):http://blog.csdn.net/jediael_lu/article/details/38758337
3、帶參數(shù)的create方法 /** Create a {@link Configuration} from supplied properties.* @param addNutchResources if true, then first <code>nutch-default.xml</code>,* and then <code>nutch-site.xml</code> will be loaded prior to applying the* properties. Otherwise these resources won't be used.* @param nutchProperties a set of properties to define (or override)*/public static Configuration create(boolean addNutchResources, Properties nutchProperties) {Configuration conf = new Configuration();setUUID(conf);if (addNutchResources) {addNutchResources(conf);}for (Entry<Object, Object> e : nutchProperties.entrySet()) {conf.set(e.getKey().toString(), e.getValue().toString());}return conf;}
此方法根據(jù)傳入?yún)?shù)決定是否加載core-default.xml與core-site.xml,然后再加載properties中的屬性。
4、NutchConfiguration使用了單例模式, private NutchConfiguration() {} // singleton 通過(guò)上述的create方法得到一個(gè)Configuration對(duì)象。 事實(shí)上,這不是一個(gè)典型的單例模式,因?yàn)閏reate返回的不是NutchConfiguration對(duì)象,而是Configuration對(duì)象,,并且是通過(guò)靜態(tài)方法來(lái)得到這個(gè)對(duì)象。 關(guān)于單例械,可參考:【設(shè)計(jì)模式:單例模式】使用單例模式加載properties文件
5、這個(gè)類(lèi)可以參考用作基于hadoop的應(yīng)用程序的加載配置文件的典型方法。
6、Nutch中調(diào)用NutchConfiguration的方法: public static void main(String[] args) throws Exception {final int res = ToolRunner.run(NutchConfiguration.create(),new SolrIndexerJob(), args);System.exit(res);} 關(guān)于ToolRunner,請(qǐng)參見(jiàn):http://blog.csdn.net/jediael_lu/article/details/38751885

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的【Nutch2.2.1源代码分析之4】Nutch加载配置文件的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。