【发布时间】:2015-09-25 02:59:10
【问题描述】:
我正在使用 Infinispan 7.0.2.Final,但我的行为非常奇怪。
我正在使用 infinispan 进行服务器和客户端之间的远程查询,使用 infinispan DSL 进行查询,由于某种原因服务器不返回结果列表,但结果大小不为零。
我正在谈论的行为在以下代码中表示。执行以下代码后:
Query query = qf.from(CacheEntity.class).having("ID").like("%AI%").toBuilder().build();
System.out.println("size: "+query.getResultSize());
System.out.println("result: "+query.list());
我得到这个输出:
size: 2000
result: []
这很奇怪,因为结果显然没有 2000 个元素:)
我通过以下方式设置客户端:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-main.xml");
RemoteCacheManager manager = ((RemoteCacheManager) context.getBean("cacheManager"));
RemoteCache cache = manager.getCache("cache");
SerializationContext srcCtx = ProtoStreamMarshaller.getSerializationContext(manager);
FileDescriptorSource fds = new FileDescriptorSource();
fds.addProtoFiles("entity.proto");
srcCtx.registerProtoFiles(fds);
srcCtx.registerMarshaller(new CachedEntityMarshaller());
RemoteCache<String, String> metadataCache = manager.getCache("___protobuf_metadata");
metadataCache.put("entity.proto", new InfinispanClientApplication().read("/entity.proto"));
MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext(manager));
服务器端:
HotRodServerConfiguration build = new HotRodServerConfigurationBuilder().
host("127.0.0.1").
port(11222).
build();
HotRodServer server = new HotRodServer();
server.start(build, cacheManager);
我还注意到,我的 EntityMarshaller 上的 writeTo 方法在每次写入时都会被调用,但 readTo 方法永远不会被调用。
我目前卡住了,我们将不胜感激。
非常感谢!
解决方案:
除了“最佳答案”回复。我正在使用 spring (SpringEmbeddedCacheManagerFactoryBean) 配置我的 infinispan 缓存。我使用 org.infinispan.configuration 类迁移到 java config。之后,我按照“最佳答案”中的建议做了,彻底解决了问题。
【问题讨论】:
标签: java infinispan