5 Replies Latest reply on May 30, 2014 12:32 PM by Sree Ram Mohanan

    NullPointerException for KeyAffinityService

    Sree Ram Mohanan Newbie

      I was trying to implement the KeyAffinityService in order to get the key associated with the local node but I get a NullPointerException. I was hoping if someone can help me figure my mistake.

      The code snippet is the following:


              // Create the affinity service to find the Key for the manager
              KeyAffinityService keyAffinityService = KeyAffinityServiceFactory.newLocalKeyAffinityService(
                      (KeyGenerator)new RndKeyGenerator(),


      The implementation of cache is done as following:


      EmbeddedCacheManager manager = new DefaultCacheManager();
        manager = new DefaultCacheManager("democluster.xml");
              }catch(IOException e){}
        Cache<Integer, String> cache = manager.getCache();


      The xml file used is the following:


            xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
            <transport clusterName="demoCluster"/>
            <globalJmxStatistics enabled="true"/>
         <namedCache name="clusteredCache">
              <clustering mode="distributed">
              <hash numOwners="1" >
                 <groups enabled="true"/>


      The error I get is the following:


      Exception in thread "main" java.lang.NullPointerException
        at org.infinispan.affinity.KeyAffinityServiceFactory.newLocalKeyAffinityService(KeyAffinityServiceFactory.java:95)
        at org.infinispan.affinity.KeyAffinityServiceFactory.newLocalKeyAffinityService(KeyAffinityServiceFactory.java:104)
        at SimpleCache.start(SimpleCache.java:46)
        at SimpleCache.main(SimpleCache.java:96)

      I was wondering if anyone had encountered anything similar or might have any ideas regarding this problem.


      Best Regards,

      Sree Ram Mohanan