0

Java 程序嵌入了 HotRod Infinispan 服务器,远程 Java 应用程序可以使用 HotRod API 访问嵌入的缓存。(兼容模式设置为 true)。这完全可以正常工作,但是当在客户端启用 NearCache 时,在服务器上观察到以下异常并且缓存操作失败。

这是说明问题的示例服务器和客户端代码。

package example;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import org.infinispan.Cache;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.NearCacheMode;

public class SimpleEmbeddedHotRodServer {

    public static void main(String[] args) throws IOException {
        org.infinispan.configuration.cache.ConfigurationBuilder embeddedBuilder = new org.infinispan.configuration.cache.ConfigurationBuilder();
        embeddedBuilder
           .dataContainer()
              .keyEquivalence(new AnyServerEquivalence())
              .valueEquivalence(new AnyServerEquivalence())
              .compatibility()
              .enable();
        DefaultCacheManager defaultCacheManager = new DefaultCacheManager(embeddedBuilder.build());
        /*
         * Use the following for XML configuration
           InputStream is = SimpleEmbeddedHotRodServer.class.getResourceAsStream("/infinispan.xml");
           DefaultCacheManager defaultCacheManager = new DefaultCacheManager(is);
        */
        Cache<String, String> embeddedCache = defaultCacheManager.getCache();

        HotRodServerConfiguration build = new HotRodServerConfigurationBuilder().build();
        HotRodServer server = new HotRodServer();
        server.start(build, defaultCacheManager);

        ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();
        remoteBuilder.nearCache().mode(NearCacheMode.INVALIDATED).maxEntries(10);
        remoteBuilder.addServers("localhost");
        RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteBuilder.build());
        RemoteCache<String, String> remoteCache = remoteCacheManager.getCache();

        System.out.print("\nInserting data into embedded cache...");
        int i = 1;
        for(char ch='a'; ch<='a'; ch++) {
           String s = Character.toString(ch);
           embeddedCache.put(s, s);
           System.out.printf("%s...", s);
        }

        System.out.print("\nVerifying data in remote cache...");
        for(char ch='a'; ch<='a'; ch++) {
           String s = Character.toString(ch);
           //assert s.equals(remoteCache.get(s));
           System.out.printf("%s...", remoteCache.get(s));
           //System.out.printf("%s...", s);
        }

        System.out.println("\nDone !");
        remoteCacheManager.stop();
        server.stop();
        defaultCacheManager.stop();
    }
}

我尝试使用 8.0.2 和 8.2.2 版本的 Infinispan。如果我缺少任何配置,您能帮我理解吗?

谢谢你。


===============================异常=================== ==============

TRACE 05/22 13:04:34 org.infinispan.commons.marshall.jboss.AbstractJBossMarshaller Stop marshaller
TRACE 05/22 13:04:34 org.infinispan.client.hotrod.near.NearCacheService Removed key=a from near cache (listenedId=[B0xc55733e8a05046d8..[16])
DEBUG 05/22 13:04:34 org.infinispan.server.hotrod.CacheDecodeContext Exception caught
io.netty.handler.codec.DecoderException: org.infinispan.server.hotrod.HotRodException: java.lang.NullPointerException
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:425)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:168)
at org.infinispan.server.hotrod.HotRodDecoder.org$infinispan$server$core$transport$StatsChannelHandler$$super$channelRead(HotRodDecoder.scala:31)
at org.infinispan.server.core.transport.StatsChannelHandler$class.channelRead(StatsChannelHandler.scala:32)
at org.infinispan.server.hotrod.HotRodDecoder.channelRead(HotRodDecoder.scala:31)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.infinispan.server.hotrod.HotRodException: java.lang.NullPointerException
at org.infinispan.server.hotrod.CacheDecodeContext.createServerException(CacheDecodeContext.scala:96)
at org.infinispan.server.hotrod.HotRodDecoder.decode(HotRodDecoder.scala:55)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:370)
... 15 more
Caused by: java.lang.NullPointerException
at org.infinispan.server.hotrod.Decoder2x$.createGetResponse(Decoder2x.scala:219)
at org.infinispan.server.hotrod.CacheDecodeContext.createGetResponse(CacheDecodeContext.scala:244)
at org.infinispan.server.hotrod.CacheDecodeContext.get(CacheDecodeContext.scala:176)
at org.infinispan.server.hotrod.HotRodDecoder.org$infinispan$server$hotrod$HotRodDecoder$$decodeKey(HotRodDecoder.scala:101)
at org.infinispan.server.hotrod.HotRodDecoder$$anonfun$decode$1.apply$mcV$sp(HotRodDecoder.scala:48)
at org.infinispan.server.hotrod.HotRodDecoder.wrapSecurity(HotRodDecoder.scala:206)
at org.infinispan.server.hotrod.HotRodDecoder.decode(HotRodDecoder.scala:45)
... 16 more
TRACE 05/22 13:04:34 org.infinispan.server.hotrod.HotRodEncoder Encode msg ErrorResponse{version=23, messageId=4, operation=ErrorResponse, status=ServerError, msg=java.lang.NullPointerException}
4

0 回答 0