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

Enabling compatibility mode in infinispan doesn't seems to do anything?

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

我正在使用带有 Java 嵌入式 HotRot 端点和缓存的 C++ HotRod 客户端,当我将 K/V 放入 java 缓存侦听器时抛出一个关于转换错误的异常B[ 和字符串。

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

这是我的代码:

主要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.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;  
}  

我做错了什么?以及需要更改什么才能使此代码有效?

谢谢。

此致。

刚才我的代码错了,其实我没有设置兼容模式,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