7 Replies Latest reply on Mar 17, 2015 5:52 PM by Flavien LEFEBVRE

    Weird values when using embedded distributed cache with HotRod client/server

    Flavien LEFEBVRE Newbie

      Hi JBoss community,


      I'm trying to use Infinispan (7.1.0.Final) as a distributed cache and to expose it through hotrod protocole.

      I started with the sample project from Tristan Tarrant (thanks to him) here https://github.com/tristantarrant/infinispan-playground-embedded-hotrod

      All worked fine until I tried to use a distributed cache. Now, all values I insert are weird (random) values (look like serialized data).

      When I used the cache as a local cache all is ok.

      Here is the code SimpleEmbeddedHotRodServer.java :

      public static void main(String[] args) throws Exception {

              // disabled for test

              //org.infinispan.configuration.cache.ConfigurationBuilder embeddedBuilder = new org.infinispan.configuration.cache.ConfigurationBuilder();

              //embeddedBuilder.dataContainer().keyEquivalence(new AnyServerEquivalence()).valueEquivalence(new AnyServerEquivalence());

              DefaultCacheManager defaultCacheManager = new DefaultCacheManager("distributed.xml");


              HotRodServerConfiguration build = new HotRodServerConfigurationBuilder().build();

              HotRodServer server = new HotRodServer();

              server.start(build, defaultCacheManager);


              ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();


              RemoteCacheManager remoteCacheManager = new RemoteCacheManager(remoteBuilder.build());

              RemoteCache<String, String> remoteCache = remoteCacheManager.getCache();


              System.out.print("Inserting data into cache...");

              String s = "asRemote";

              remoteCache.put(s, s);

              System.out.print("\nVerifying data...");

              System.out.printf("%s...", remoteCache.get(s));


              System.out.print("\nNow using as a local cache");

              Cache<String, String> cache = defaultCacheManager.getCache();

              s = "asLocal";

              cache.put(s, s);

              System.out.print("\nVerifying data...");

              System.out.printf("%s...", cache.get(s));


              System.out.print("\nWhat is in my cache ?");      

              System.out.printf("\nCache have %s entries", cache.size());

              for(Map.Entry<String, String> entry : cache.entrySet()) {

                  System.out.printf("\n\t\tCache entry %s : value %s", entry.getKey(), entry.getValue());



              System.out.println("\nDone !");






      and the conf distributed.xml :

      <?xml version="1.0" encoding="UTF-8"?>

      <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


          xsi:schemaLocation="urn:infinispan:config:7.1                 http://www.infinispan.org/schemas/infinispan-config-7.1.xsd ">


          <!-- minimal config -->

          <cache-container default-cache="my-cache" statistics="true" >

              <transport />

              <distributed-cache name="my-cache" l1-lifespan="30000" owners="2" mode="SYNC" statistics="true" />





      Now What I get when I mvn exec:java :


      Inserting data into cache...

      Verifying data...null...

      Now using as a local cache

      Verifying data...asLocal...

      What is in my cache ?

      Cache have 2 entries

                      Cache entry [B@1d422062 : value [B@31d7ed1d

                      Cache entry asLocal : value asLocal

      Done !



      I can't figured out what goes wrong.

      Any Idea ?


      Thanks for your help.