在infinispan中启用兼容模式似乎没有做任何事情?

时间:2015-07-08 19:21:35

标签: java c++ infinispan

我是infinispan的新手,但功能满足了我的需求。

我正在使用带有缓存的Java嵌入式HotRot端点的C ++ HotRod客户端,当我放置K / V时,java缓存监听器会抛出关于B [和String。

之间的转换错误的异常。

我发现我可能必须启用兼容模式,所以我做了,但它似乎没有做任何事情。

这是我的代码:

主要的java软件:

public static void main(final String[] args)  
{  
     final EmbeddedCacheManager manager = new DefaultCacheManager();  
     final PersistenceConfigurationBuilder persistConfig = new ConfigurationBuilder().persistence();  
     final SingleFileStoreConfigurationBuilder fileStore = new SingleFileStoreConfigurationBuilder(persistConfig).location("cache");  
     final Configuration config = persistConfig.addStore(fileStore).build();  
     config.compatibility().enabled();  
     manager.defineConfiguration("records", config);  

     final Cache<String, String> c = manager.getCache("records");  
     c.addListener(new CacheListener());  

     new HotRodServer().start(new HotRodServerConfigurationBuilder().build(), manager);  

     while(true)  
     {  
          try  
          {  
               Thread.sleep(1000);  

               System.out.println(c.size());  
          }  
          catch(final InterruptedException e)  
          {  
          }  
     }  
}  

我的缓存监听器:

@CacheEntryCreated  
public void observeAdd(final CacheEntryCreatedEvent<Object, String> event)  
{  
     if(event.isPre())  
          return;  

     System.err.println(event.getKey().getClass().getSimpleName());  
     System.err.println("new entry : " + event.getKey() + " -> " + event.getValue());  
}  

异常摘录:

Caused by: java.lang.ClassCastException: [B cannot be cast to java.lang.String
                at recordprocessing.CacheListener.observeAdd(CacheListener.java:38) ~[classes/:na]
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
                at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.infinispan.notifications.impl.AbstractListenerImpl$ListenerInvocationImpl$1.run(AbstractListenerImpl.java:286) ~[infinispan-core-7.2.3.Final.jar:7.2.3.Final]
                ... 60 common frames omitted

我的c ++ hotrod客户端完全来自文档:

#include "infinispan/hotrod/ConfigurationBuilder.h"  
#include "infinispan/hotrod/RemoteCacheManager.h"  
#include "infinispan/hotrod/RemoteCache.h"  
#include <stdlib.h>  

using namespace infinispan::hotrod;  

int main(int argc, char** argv)  
{  
     ConfigurationBuilder b;  
     b.addServer().host("127.0.0.1").port(11222);  
     RemoteCacheManager cm(builder.build(), false);  
     RemoteCache<std::string, std::string> cache = cm.getCache<std::string, std::string>(std::string("records"));  

     cm.start();  

     std::string k1("key13");  
     std::string v1("boron");  

     rc.put(k1, v1);  

     cm.stop();  

     return 0;  
}  

我做错了什么?什么需要改变才能使这段代码有效?

感谢。

最好的问候。

1 个答案:

答案 0 :(得分:2)

我的代码错了,实际上我没有设置兼容模式,config.compatibility()。enabled();只是返回当前模式。

以下是我必须更改代码以启用兼容模式的方法:

final EmbeddedCacheManager manager = new DefaultCacheManager();
final PersistenceConfigurationBuilder persistConfig = new ConfigurationBuilder().persistence();
final SingleFileStoreConfigurationBuilder fileStore = new SingleFileStoreConfigurationBuilder(persistConfig).location("cache");
final Configuration config = persistConfig.addStore(fileStore).compatibility().enable().build();
manager.defineConfiguration("records", config);

以下是关于JBoss论坛的问题:https://developer.jboss.org/thread/261123