2 Replies Latest reply on Mar 12, 2013 2:01 AM by varsha g

    Infinispan acessing data under cache.

    varsha g Newbie

      Hello All,

      I'm new to Infinispan.I'm trying to create a simple example on infinispan.

       

          I'm having servlet 1

       

              String configFile = "/home/user/infinispan_config.xml"; //path to config file

              DefaultCacheManager m = new DefaultCacheManager(configFile);   

              Cache<String, ArrayList<String>> c = m.getCache("evictionCache");   

       

                 ArrayList<String> arr=new ArrayList<String>();

                 arr.add("abc");

                 arr.add("abc1");

                 arr.add("abc2");

                 arr.add("abc3");          

                 c.put("arr",arr);

       

                 System.out.println(((ArrayList<String>)c.get("arr")).size());

       

          It's showing size here

       

          Now I'm having servlet 2

       

              String configFile = "/home/user/infinispan_config.xml"; //path to config file

              DefaultCacheManager m = new DefaultCacheManager(configFile);

              Cache<String, ArrayList<String>> c =m.getCache("evictionCache");

              System.out.println("Cache----"+c);

              System.out.println(((ArrayList<String>)c.get("arr")).size());

       

          Here I'm abel to get cache but not size of arr as it's throwing nullpointer exception

       

          My infinispan_config.xml contians following.

       

          <infinispan>

            <namedCache name="evictionCache">

               <eviction wakeUpInterval="500" maxEntries="5000" strategy="FIFO" />

               <expiration lifespan="60000" maxIdle="10000"/>

            </namedCache>

          </infinispan>

       

          What to do to make above work as it's not storing data to  cache to access in application ?

       

          I'm very new to this.. Please help

        • 1. Re: Infinispan acessing data under cache.
          Pedro Ruivo Novice

          Hi,

           

          I'm assuming that the servlets are running in different machines/java virtual machine...

           

          The cache needs to be configured as a clustered cache and to enable it, you need to set a transport in the global section to allow the machines/jvms communicate between them:

           

          <config...>

            <global>

            <transport clusterName="infinispan-cluster"> <!-- you can set any name that you want -->

                   <properties>

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

                   </properties>

                </transport>

            </global>

            <namedCache>

            ...

            </namedCache>

          </config>

           

          The jgroups-udp.xml is already in the infinispan jar. It should work in most of the systems. If not, you have to set a new JGroups configuration. Check the JGroups' manual here: http://jgroups.org/manual-3.x/html/index.html

           

          In addition to a transport you need to set how the data is keep. You can set a replicated mode (the data is replicated in all the machines) or distributed mode (the data is replicated in a subset of machines, 1 or more). In distributed mode, if the cache in a node does not have the data, it will fetch it.

           

          <namedCache>

          ...

            <clustering mode="r"> <!-- set mode to "d" for distribution -->

          ...

          </clustering>

          </namedCache>

           

          This is an overview. The full documentation can be found here: http://docs.jboss.org/infinispan/5.2/configdocs/

          If you have more question, post here in the forum. I was not clear let me know.

           

          Cheers,

          Pedro

          • 2. Re: Infinispan acessing data under cache.
            varsha g Newbie

            Thanks Pedro.Your answer helped me lot.