1 Reply Latest reply on Oct 23, 2013 12:35 PM by Pedro Ruivo

    Infinispan Cache Distribution-Asynchronous Mode Issue

    Senthil Sekar Newbie



      We are using infinispan in Distributed(Asynchronous) mode with 2-nodes. I am able to put a key in the cache, but not able read it immediately its returning null (Probably next statement).I tried in 2-ways




         Cache<String, String> cache = getCacheManager().getCache("Demo");

         cache.put("key-1", "value-1");

         System.out.println("Value for Key-1 : "+cache.get("key-1"));       // This is Returning NULL in Asynchronous Mode




      Cache<String, String> cache = getCacheManager().getCache("Demo");

      NotifyingFuture<String> f1= cache.putAsync("key-1", "value-1");





      catch(Exception e)


        System.out.println("Excep occured: "+e);


      System.out.println("Value for Key-1 : "+cache.get("key-1"));       // This is Returning NULL in Asynchronous Mode


      Cache Config XML


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



        <transport clusterName="infinispan-cluster">


        <property name="configurationFile" value="jgroups.xml" />





        <!-- Configure a Asynchronous replication cache -->

        <clustering mode="distribution">

            <async asyncMarshalling="false" useReplQueue="false"/>          

                <l1 enabled="false" />

                <hash numOwners="2" numSegments="20" />





      JGroups XML  --> i have attached as an attachement


      Looking forward for suggestions and help.




        • 1. Re: Infinispan Cache Distribution-Asynchronous Mode Issue
          Pedro Ruivo Novice

          Hello Senthil


          I''ve noticed that you have configured async clustering in your Infinispan configuration. This means that all the communication is done asynchronous so, Infinispan will return immediately and will not wait for a confirmation of the replication really occurs. In other words, in 1-way, it sends the replication message and returns from put and in 2-way, it does exactly the same thing (the future.get returns as soon as the message is sent).


          To have what you desire, you have to configure the clustering as sync. With sync, the put() in 1-way returns only after it has the confirmation that the owners has applied the modification. In 2-way, the put() is processed in other thread and the future.get() only returns after the same confirmation (as I described in 1-way)


          If you have more questions or I was not clear let me know.