连接器里面采用的什么样的数据结构,我们先从Document迭代器开始入手,具体的Document迭代器类都实现了DocumentList接口,该接口定义了两个方法

public interface DocumentList {

  public Document nextDocument() throws RepositoryException;

  public String checkpoint() throws RepositoryException;
}

前者用于获取Document对象,后者获取断点状态

上文中分析的DiffingConnectorDocumentList类即实现了DocumentList接口,从List<CheckpointAndChange> guaranteedChanges集合的迭代器中迭代获取CheckpointAndChange对象然后包装为Document类型对象

Document也是一接口类型

public interface Document {

  public Property findProperty(String name) throws RepositoryException;

  public Set<String> getPropertyNames() throws RepositoryException;
}

从Document接口定义的方法可以看出,Document接口类似于Map容器结构,如果进一步考察String类型的key对应的value类型Property,可以发现Document接口很类似于HashMap结构

public interface Property {

  public Value nextValue() throws RepositoryException;
}

下面继续考察Document接口的具体实现类,以JsonDocument类说明:

/**
*省略了其他部分成员属性及方法
* A simple {@link Document} implementation created from a {@link JSONObject}.
*/
public class JsonDocument implements Document { private final Map<String, List<Value>> properties; /**
* Constructor used by {@link DBHandle} when deserializing a
* {@code DocumentHandle} from the recovery file.
*/
public JsonDocument(JSONObject jsonObject) {
this(buildJsonProperties(jsonObject), jsonObject);
} /**
* Constructor used by the {@link DocumentBuilder} for creating a
* {@link JsonDocument} object used by {@link RepositoryHandler}
* for building a collection over JsonDocument.
*/
public JsonDocument(Map<String, List<Value>> properties,
JSONObject jsonObject) {
this.properties = properties;
this.jsonObject = jsonObject;
objectId = getSingleValueString(SpiConstants.PROPNAME_DOCID);
if (Strings.isNullOrEmpty(objectId)) {
throw new IllegalArgumentException(
"Unable to parse for docID from the properties:" + properties);
}
} @Override
public Set<String> getPropertyNames() {
return properties.keySet();
} @Override
public Property findProperty(String name) throws RepositoryException {
List<Value> property = properties.get(name);
if (name.equals(SpiConstants.PROPNAME_CONTENT) && filterMimeType()) {
property = null;
}
return (property == null) ? null : new SimpleProperty(property);
} }

JsonDocument类还有什么好说的呢,内部实际是对Map<String, List<Value>> properties的封装

属性类型SimpleProperty实现了Property接口

/**
* Simple implementation of the {@link Property} interface.
* Implementors may use this directly or for reference.
*
* @since 1.0
*/
public class SimpleProperty implements Property { final Iterator<Value> iterator; /**
* Constructs a property with a single value.
*
* @param value the property's {@link Value}
* @since 2.4
*/
public SimpleProperty(Value value) {
this(Collections.singletonList(value));
} /**
* Constructs a property with multiple values.
*
* @param values a {@code List} of the property's {@link Value Values}
*/
public SimpleProperty(List<Value> values) {
this.iterator = values.iterator();
} @Override
public Value nextValue() {
return (iterator.hasNext()) ? iterator.next() : null;
}
}

成员属性final Iterator<Value> iterator保存值的迭代器,功能与HashMap的entry链表类似

---------------------------------------------------------------------------

本系列企业搜索引擎开发之连接器connector系本人原创

转载请注明出处 博客园 刺猬的温驯

本人邮箱: chenying998179@163#com (#改为.)

本文链接 http://www.cnblogs.com/chenying99/p/3789695.html

企业搜索引擎开发之连接器connector(三十)的更多相关文章

  1. 企业搜索引擎开发之连接器connector(十九)

    连接器是基于http协议通过推模式(push)向数据接收服务端推送数据,即xmlfeed格式数据(xml格式),其发送数据接口命名为Pusher Pusher接口定义了与发送数据相关的方法 publi ...

  2. 企业搜索引擎开发之连接器connector(十八)

    创建并启动连接器实例之后,连接器就会基于Http协议向指定的数据接收服务器发送xmlfeed格式数据,我们可以通过配置http代理服务器抓取当前基于http协议格式的数据(或者也可以通过其他网络抓包工 ...

  3. 企业搜索引擎开发之连接器connector(十六)

    本人有一段时间没有接触企业搜索引擎之连接器的开发了,连接器是涉及企业搜索引擎一个重要的组件,在数据源与企业搜索引擎中间起一个桥梁的作用,类似于数据库之JDBC,通过连接器将不同数据源的数据适配到企业搜 ...

  4. 企业搜索引擎开发之连接器connector(二十九)

    在哪里调用监控器管理对象snapshotRepositoryMonitorManager的start方法及stop方法,然后又在哪里调用CheckpointAndChangeQueue对象的resum ...

  5. 企业搜索引擎开发之连接器connector(二十八)

    通常一个SnapshotRepository仓库对象对应一个DocumentSnapshotRepositoryMonitor监视器对象,同时也对应一个快照存储器对象,它们的关联是通过监视器管理对象D ...

  6. 企业搜索引擎开发之连接器connector(二十六)

    连接器通过监视器对象DocumentSnapshotRepositoryMonitor从上文提到的仓库对象SnapshotRepository(数据库仓库为DBSnapshotRepository)中 ...

  7. 企业搜索引擎开发之连接器connector(二十五)

    下面开始具体分析连接器是怎么与连接器实例交互的,这里主要是分析连接器怎么从连接器实例获取数据的(前面文章有涉及基于http协议与连接器的xml格式的交互,连接器对连接器实例的设置都是通过配置文件操作的 ...

  8. 企业搜索引擎开发之连接器connector(二十四)

    本人在上文中提到,连接器实现了两种事件依赖的机制 ,其一是我们手动操作连接器实例时:其二是由连接器的自动更新机制 上文中分析了连接器的自动更新机制,即定时器执行定时任务 那么,如果我们手动操作连接器实 ...

  9. 企业搜索引擎开发之连接器connector(二十二)

    下面来分析线程执行类,线程池ThreadPool类 对该类的理解需要对java的线程池比较熟悉 该类引用了一个内部类 /** * The lazily constructed LazyThreadPo ...

随机推荐

  1. jQuery easyui combobox获取值|easyui-combobox获取多个值

    Query easyui combobox事例:            name="language"             data-options="        ...

  2. javac 命令出现 找不到文件 问题及解决办法

    如果环境配置好了,使用java -version回车可以正常查看到版本信息. 使用javac Demo.java 如果提示文件找不到 可能原因1: 源文件与当前命令行不在同目录下,这时候就要切换到同一 ...

  3. linux 如何显示一个文件的某几行(中间几行)

    linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...

  4. generator class 的含义

    native有天生的,本土的,也就是说生来就有的, 那也就是说自动生成,不需要人工来帮忙或者管控的. 而assigned是指指定的,分配的, 如果你不赋予他甚麼东西,那麼他是不能实现的. 需要人工,自 ...

  5. JavaScript依赖注入的实现思路

    JavaScript依赖注入的实现思路 如今各个框架都在模块化,连前端的javascript也不例外.每个模块负责一定的功能,模块与模块之间又有相互依赖,那么问题来了:javascript的依赖注入如 ...

  6. error: src refspec master does not match any. 错误处理办法

    自从上次学了git之后,很少用.今天在使用 本地仓库使用如下命令初始化: $ git init 之后使用如下命令添加远程库: $ git remote add origin git@github.co ...

  7. 用Navicat_SSH 连接数据库服务器

    SSH设置(只限于Mysql.oracle.PostgreSQL及 SQL Server 并只支持 SSH2通讯协定) Secure SHell(SSH)是一个通过网络登录其他计算机的程序,在远程服务 ...

  8. 在Sublime Text3上面更加方便愉快的写php

    写php代码,elcipse体积太大,开起来太麻烦,记事本又没有什么标识,稍不留神就会出现;没加.大括号没对全的尴尬情况.所以我选择使用Sublime. 推荐几个 sublime插件:sublimeL ...

  9. FreeMarker标签与使用

    模板技术在现代的软件开发中有着重要的地位,而目前最流行的两种模板技术恐怕要算freemarker和velocity了,webwork2.2对两者都有不错的支持,也就是说在webwork2中你可以随意选 ...

  10. kendo chart label position 图表的值标签位置及显示模板

    1.不显示0 seriesDefaults: { type: "column", labels: { visible: true, position:'' background: ...