Nutch 1.0 源代码分析[3] Plugin(2)
来自: http://c.tieba.baidu.com/p/3439551436
在URLNormalizers构造函数中,有一句没有看:
this.extensionPoint =PluginRepository.get(conf).getExtensionPoint(
URLNormalizer.X_POINT_ID);
看一下PluginRepository.get函数:
public
static synchronizedPluginRepository get(Configuration conf) {
PluginRepository result = CACHE.get(conf);
if (result ==null) {
result = newPluginRepository(conf);
CACHE.put(conf,result);
}
returnresult;
}
先试着从CACHE取,如果没有被缓存过,那么就调用PluginRepository的构造函数:
publicPluginRepository(Configuration conf)throwsRuntimeException {
fActivatedPlugins =newHashMap<String, Plugin>();
fExtensionPoints =newHashMap<String, ExtensionPoint>();
this.conf =conf;
this.auto =conf.getBoolean("plugin.auto-activation",true);
String[] pluginFolders = conf.getStrings("plugin.folders");
PluginManifestParsermanifestParser = new PluginManifestParser(conf,
this);
Map<String, PluginDescriptor>allPlugins = manifestParser
.parsePluginFolder(pluginFolders);
Pattern excludes = Pattern.compile(conf.get("plugin.excludes",""));
Pattern includes = Pattern.compile(conf.get("plugin.includes",""));
Map<String, PluginDescriptor>filteredPlugins = filter(excludes,
includes, allPlugins);
fRegisteredPlugins =getDependencyCheckedPlugins(filteredPlugins,
this.auto ?allPlugins : filteredPlugins);
installExtensionPoints(fRegisteredPlugins);
try {
installExtensions(fRegisteredPlugins);
} catch(PluginRuntimeException e) {
LOG.fatal(e.toString());
thrownewRuntimeException(e.getMessage());
}
displayStatus();
}
这里拷贝一点《Nutch插件系统浅析》里的介绍:
1. plugin.folders:插件所在的目录,缺省位置在 plugins 目录下。
<property>
<name>plugin.folders</name>
<value>plugins</value>
</property>
2. plugin.auto-activation:当被配置为过滤(即不加载),但是又被其他插件依赖的时候,是否自动启动,缺省为 true。
<property>
<name>plugin.auto-activation</name>
<value>true</value>
</property>
3. plugin.includes:要包含的插件名称列表,支持正则表达式方式定义。
<property>