Reputation: 1
A Java program embeds a HotRod Infinispan server and the remote Java applications can access the embedded caches using the HotRod API. (Compatibility mode is set to true). This perfectly works fine however when the NearCache is enabled at the clients, the following exception is observed at the server and the cache operations fail.
Here is an example server and client code that illustrates the problem.
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();
}
}
I tried with 8.0.2 and 8.2.2 version of Infinispan. Can you please help me understand if I'm missing any configuration?
Thank you.
============================== Exception ================================
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}
Upvotes: 0
Views: 400