4 Replies Latest reply on Dec 15, 2014 4:15 AM by scpark

    RemoteCache data is null when using programmatic server configuration

    scpark

      Hi,

       

      I started Hotrod server using programmatic configuration and then put some data to cache using RemoteCache.

       

      But in spite of cache does not empty, value is null.

       

      This is my test code.

       

      public static void main(String[] args) {
      
           HotRodServerConfiguration hotrodConfig = new HotRodServerConfigurationBuilder()
                .host("127.0.0.1")
                .port(11222)     
                .workerThreads(100)
                .build();
      
           GlobalConfiguration globalConfig = new GlobalConfigurationBuilder()
                .nonClusteredDefault()
                .globalJmxStatistics().enable()
                .build();
      
           Configuration config = new org.infinispan.configuration.cache.ConfigurationBuilder()
                .clustering().cacheMode(CacheMode.LOCAL)
                .jmxStatistics().enable()
                .build();
      
           new HotRodServer().start(hotrodConfig, new DefaultCacheManager(globalConfig, config));
      
           org.infinispan.client.hotrod.configuration.ConfigurationBuilder builder = new org.infinispan.client.hotrod.configuration.ConfigurationBuilder();
           Properties properties = new Properties();
      
           properties.put("infinispan.client.hotrod.server_list", "127.0.0.1:11222");
      
           RemoteCacheManager manager = new RemoteCacheManager(builder.withProperties(properties).build());
           RemoteCache<String, Object> cache = manager.getCache();
      
           cache.put("key1", "value1");
           cache.put("key2", "value2");
           cache.put("key3", "value3");
      
           System.out.println("ProtocolVersion : " + cache.getProtocolVersion());
           System.out.println("Version : " + cache.getVersion());
           System.out.println("isEmpty : " + cache.isEmpty());
           System.out.println("Size : " + cache.size());
           System.out.println(cache.keySet().toString());
          
           System.out.println(cache.get("key1"));
           System.out.println(cache.get("key2"));
           System.out.println(cache.get("key3"));
      }
      

       

      Output :

      ProtocolVersion : HotRod client, protocol version :2.0

      Version : 7.0.2.Final

      isEmpty : false

      Size : 3

      [key3, key2, key1]

      null

      null

      null

       

      cache.getBulk() can get the value, but update or delete operation did not work.

       

      Could any one help me on this issue.

        • 1. Re: RemoteCache data is null when using programmatic server configuration
          nadirx

          You need to enable compatibility mode and provide appropriate datacontainer equivalence classes. Look at tristantarrant/infinispan-playground-embedded-hotrod · GitHub for a working example.

          1 of 1 people found this helpful
          • 2. Re: RemoteCache data is null when using programmatic server configuration
            scpark

            Thanks for reply..

             

            But when I enable compatibility mode, I think I need to write and define marshaller for VO(Value Object) that inserted as a value.

            Also Infinispan-server's standalone.xml and clustered.xml does not contain <compatibility enabled="true"/> and works fine.

             

            Why should I enable compatibility mode? and if compatibility is necessary mode, can i enable it without marshaller?

            • 3. Re: RemoteCache data is null when using programmatic server configuration
              nadirx

              You need compatibility mode because you are writing from embedded and reading from HotRod.

              In Infinispan Server you are only accessing the data remotely over a single protocol and therefore you do not need to enable compatibility mode. Server does however enable datacontainer equivalence using the same class that is in my example.

              As for the marshaller, you don't need to write your own: you can use the included GenericJBossMarshaller. Also, if you're using the "embedded server" approach, enabling compatibility mode will ensure the marshaller is applied to the data when it is being accessed over HotRod. In this case the embedded side will only see the "real" (unmarshalled) object.

              • 4. Re: Re: RemoteCache data is null when using programmatic server configuration
                scpark

                Resolved this issue.

                 

                  Configuration config = new org.infinispan.configuration.cache.ConfigurationBuilder()

                    .clustering().cacheMode(CacheMode.LOCAL)

                    .sync()

                      .jmxStatistics().enable()

                      .dataContainer().keyEquivalence(new AnyServerEquivalence()).valueEquivalence(new AnyServerEquivalence())

                      //.dataContainer().keyEquivalence(ByteArrayEquivalence.INSTANCE).valueEquivalence(ByteArrayEquivalence.INSTANCE)

                      .build();

                 

                Special thanks @Tristan Tarrant.