企业搜索引擎开发之连接器connector(二十四)
本人在上文中提到,连接器实现了两种事件依赖的机制 ,其一是我们手动操作连接器实例时;其二是由连接器的自动更新机制
上文中分析了连接器的自动更新机制,即定时器执行定时任务
那么,如果我们手动操作连接器实例时,是怎么发出事件更新连接器实例的呢
通过eclipse开发工具,追踪调用ChangeDetector接口的detect()方法的方法
ChangeDetectorTask类的run方法里面调用我们再上文中已经分析了,其他方法便是ConnectorCoordinatorImpl实例对象的方法
即ConnectorCoordinatorImpl实例对象的如下方法,分别调用了ChangeDetector接口的detect()方法
/**
* 移除连接器实例
* Removes this {@link Connector} instance. Halts traversals,
* removes the Connector instance from the known connectors,
* and removes the Connector's on-disk representation.
*/
/* @Override */
public void removeConnector() {
synchronized(this) {
resetBatch();
if (instanceInfo != null) {
instanceInfo.removeConnector();
}
}
// This must not be called while holding the lock.
changeDetector.detect();
} /**
* 重启遍历
* Retraverses the {@link Connector}'s content from scratch.
* Halts any traversal in progress and removes any saved traversal state,
* forcing the Connector to retraverse the Repository from its start.
*/
/* @Override */
public void restartConnectorTraversal() throws ConnectorNotFoundException {
// To avoid deadlock, this method calls InstanceInfo's getters and setters,
// rather than the local ones.
synchronized(this) {
resetBatch(); // Halt any traversal.
getInstanceInfo().setConnectorState(null); // Discard the checkpoint. // If Schedule was 'run-once', re-enable it to run again. But watch out -
// empty disabled Schedules could look a bit like a run-once Schedule.
Schedule schedule = getInstanceInfo().getConnectorSchedule();
if (schedule != null && schedule.isDisabled() &&
schedule.getRetryDelayMillis() == -1 &&
schedule.nextScheduledInterval() != -1) {
schedule.setDisabled(false);
getInstanceInfo().setConnectorSchedule(schedule);
}
} // TODO: Remove this if we switch completely to JDBC PersistentStore.
// FileStore doesn't notice the deletion of a file that did not exist.
if (lister != null) {
connectorCheckpointChanged(null);
} // This must not be called while holding the lock.
changeDetector.detect();
} /**
* 设置配置信息
* Sets the {@link Configuration} for this {@link ConnectorCoordinator}.
* If this {@link ConnectorCoordinator} supports persistence this will
* persist the new Configuration.
*/
/* @Override */
public ConfigureResponse setConnectorConfiguration(TypeInfo newTypeInfo,
Configuration configuration, Locale locale, boolean update)
throws ConnectorNotFoundException, ConnectorExistsException,
InstantiatorException {
LOGGER.info("Configuring connector " + name);
String typeName = newTypeInfo.getConnectorTypeName();
Preconditions.checkArgument(typeName.equals(configuration.getTypeName()),
"TypeInfo must match Configuration type");
ConfigureResponse response = null;
synchronized(this) {
resetBatch();
if (instanceInfo != null) {
if (!update) {
throw new ConnectorExistsException();
}
if (typeName.equals(typeInfo.getConnectorTypeName())) {
configuration =
new Configuration(configuration, getConnectorConfiguration());
response = resetConfig(instanceInfo.getConnectorDir(), typeInfo,
configuration, locale);
} else {
// An existing connector is being given a new type - drop then add.
// TODO: This shouldn't be called from within the synchronized block
// because it will kick the change detector.
removeConnector();
response = createNewConnector(newTypeInfo, configuration, locale);
if (response != null) {
// TODO: We need to restore original Connector config. This is
// necessary once we allow update a Connector with new ConnectorType.
// However, when doing so consider: createNewConnector could have
// thrown InstantiatorException as well. Also, you need to kick
// the changeDetector (but not in this synchronized block).
LOGGER.severe("Failed to update Connector configuration.");
// + " Restoring original Connector configuration.");
}
}
} else {
if (update) {
throw new ConnectorNotFoundException();
}
response = createNewConnector(newTypeInfo, configuration, locale);
}
}
if (response == null) {
// This must not be called while holding the lock.
changeDetector.detect();
} else {
return new ExtendedConfigureResponse(response, configuration.getXml());
}
return response;
} /**
* 设置定时调度
* Sets the traversal {@link Schedule} for the {@link Connector}.
*
* @param connectorSchedule Schedule to store or null to unset any existing
* Schedule.
* @throws ConnectorNotFoundException if the connector is not found
*/
/* @Override */
public void setConnectorSchedule(Schedule connectorSchedule)
throws ConnectorNotFoundException {
synchronized(this) {
// Persistently store the new schedule.
getInstanceInfo().setConnectorSchedule(connectorSchedule);
}
// This must not be called while holding the lock.
changeDetector.detect();
}
接下来ChangeDetector接口的detect()方法其实又调用了自身的实现ConnectorCoordinatorImpl实例对象的实现ChangeHandler接口的方法
ConnectorCoordinatorImpl-->ChangeDetector的detect()-->ChangeListener的相关方法-->ChangeHandler(ConnectorCoordinatorImpl实例对象)的相关方法
所以手动操作与自动更新机制实际上是殊途同归,最后都是调用了ChangeHandler(ConnectorCoordinatorImpl实例对象)的相关方法
---------------------------------------------------------------------------
本系列企业搜索引擎开发之连接器connector系本人原创
转载请注明出处 博客园 刺猬的温驯
本人邮箱: chenying998179@163#com (#改为.)
本文链接 http://www.cnblogs.com/chenying99/p/3776515.html
企业搜索引擎开发之连接器connector(二十四)的更多相关文章
- 企业搜索引擎开发之连接器connector(十九)
连接器是基于http协议通过推模式(push)向数据接收服务端推送数据,即xmlfeed格式数据(xml格式),其发送数据接口命名为Pusher Pusher接口定义了与发送数据相关的方法 publi ...
- 企业搜索引擎开发之连接器connector(十八)
创建并启动连接器实例之后,连接器就会基于Http协议向指定的数据接收服务器发送xmlfeed格式数据,我们可以通过配置http代理服务器抓取当前基于http协议格式的数据(或者也可以通过其他网络抓包工 ...
- 企业搜索引擎开发之连接器connector(十六)
本人有一段时间没有接触企业搜索引擎之连接器的开发了,连接器是涉及企业搜索引擎一个重要的组件,在数据源与企业搜索引擎中间起一个桥梁的作用,类似于数据库之JDBC,通过连接器将不同数据源的数据适配到企业搜 ...
- 企业搜索引擎开发之连接器connector(二十九)
在哪里调用监控器管理对象snapshotRepositoryMonitorManager的start方法及stop方法,然后又在哪里调用CheckpointAndChangeQueue对象的resum ...
- 企业搜索引擎开发之连接器connector(二十八)
通常一个SnapshotRepository仓库对象对应一个DocumentSnapshotRepositoryMonitor监视器对象,同时也对应一个快照存储器对象,它们的关联是通过监视器管理对象D ...
- 企业搜索引擎开发之连接器connector(二十六)
连接器通过监视器对象DocumentSnapshotRepositoryMonitor从上文提到的仓库对象SnapshotRepository(数据库仓库为DBSnapshotRepository)中 ...
- 企业搜索引擎开发之连接器connector(二十五)
下面开始具体分析连接器是怎么与连接器实例交互的,这里主要是分析连接器怎么从连接器实例获取数据的(前面文章有涉及基于http协议与连接器的xml格式的交互,连接器对连接器实例的设置都是通过配置文件操作的 ...
- 企业搜索引擎开发之连接器connector(二十二)
下面来分析线程执行类,线程池ThreadPool类 对该类的理解需要对java的线程池比较熟悉 该类引用了一个内部类 /** * The lazily constructed LazyThreadPo ...
- 企业搜索引擎开发之连接器connector(二十)
连接器里面衔接数据源与数据推送对象的是QueryTraverser类对象,该类实现了Traverser接口 /** * Interface presented by a Traverser. Used ...
随机推荐
- C# 基础备忘录
1. decimal 类型调用ToString()方法后没把末尾的0去掉的解决办法: 例子:decimal? money = Convert.ToDecimal(10.8950); string mo ...
- char、varchar、varchar2区别
char varchar varchar2 的区别 区别:1.CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串“abc",对于CHAR (20),表示你存储的 ...
- java web 程序---javabean实例--登陆界面并显示用户名和密码
重点:注意大小写,不注意细节,这点小事,还需要请教 发现一个问题,也是老师当时写的时候,发现代码没错,但是就是运行问题. 大家看,那个java类,我们要求是所有属性均为私有变量,但是方法为公有的,如果 ...
- 五、jdk工具之jmap(java memory map)、 mat之四--结合mat对内存泄露的分析、jhat之二--结合jmap生成的dump结果在浏览器上展示
目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...
- 关于HDU 5952的那些事
内容过后再贴,先发表一下心情和感悟. 这个题,我TLE了十多发,后来看了别人的题解,思路是一样的,他做了剪枝的我也做了,为何他的能过的我的超时?后来发现一个不是主要问题的问题:大家的图存储用的都是前向 ...
- modelsim 的高效使用
大概的思路: 1.往modelsim 添加仿真库. 2.将Verilog 文件,testbench文件提出.建好文件夹.比如uart仿真: uart_sim文件夹下:rtl文件夹,test_bench ...
- 并发包学习(三)-AbstractQueuedSynchronizer总结
J.U.C学习的第二篇AQS.AQS在Java并发包中的重要性,毋庸置疑,所以单独拿出来理一理.本文参考总结自<Java并发编程的艺术>第五章第二节队列同步器. 什么是AbstractQu ...
- 一线工程师带你深入学习和使用Kubernetes
http://page.factj.com/tor/xoxaHR0cDovL2RvY2tvbmUuaW8vYXJ0aWNsZS8yMzM0 Kubernetes是Google开源的容器集群管理系统,它 ...
- 解决Linux下MySQL登录ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor)问题
两种方案: 一: 1.修改mysql配置文件:vim /etc/my.cnf 2.找到[mysqld]下添加 skip-grant-tables 配置 3.重启服务service mysqld res ...
- jsp 学习 第2步 - tag 使用
tag 类似 asp.net 用户控件,用于动态显示HTML 我首先在项目 /WebContent/WEB-INF/ 建立 tags目录 用于存放 tag文件 新建一个message.tag 文件 ...