0 Replies Latest reply on Mar 12, 2013 3:59 AM by varsha g

    Sharing data between wars using infinispan

    varsha g Newbie

        Hello ,

           I'm having an ear which contains two wars and a jar,I want to share some variables between war and instantiated by jar.

           This can be done by Infinispan.But I'm not getting how to make this work.

           I've created simple app,

          Which has 2 servlets 1 puts data to cache and other accesses same cache to get data.I shared DefaultCacheManager's object using session to make it work.

          Now how to do this under two wars?

       

          These are my servlet contents

          Servlet1

                  HttpSession session1=request.getSession(true);

                  DefaultCacheManager m =new DefaultCacheManager("cluster.xml");

                  Cache<Integer, Ticket> cache = m.getCache();

                  session1.setAttribute("DefaultCacheManager", m);

                  cache.put(1, new Ticket("abc","Evening"));

                  cache.put(2, new Ticket("pqr","Morning"));

                  cache.put(3, new Ticket("lmn","Afternoon"));

                  System.out.println("Added to cache.");

       

          Servlet2

                  HttpSession session1=request.getSession(false);

                  DefaultCacheManager m=(DefaultCacheManager)session1.getAttribute("DefaultCacheManager");

                  Cache<Integer, Ticket> cache = m.getCache();

                  System.out.println("---------"+cache.size());

                  Set<Integer> set = cache.keySet();

                  for (Integer ticket: set) {

                      System.out.println(cache.get(ticket));

                  }

          cluster.xml

                  <infinispan

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

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

                        xmlns="urn:infinispan:config:5.1">  

                     <global>

                        <transport clusterName="demoCluster"/>

                        <globalJmxStatistics enabled="true"/>

                     </global>

                     <default>

                        <jmxStatistics enabled="true"/>

                        <clustering mode="distribution">

                       <l1 enabled="true" lifespan="60000"/>

                       <hash numOwners="2" rehashRpcTimeout="120000"/>

                       <sync/>

                        </clustering>

                     </default>

                  </infinispan>

       

          I'm very new to this concept.Please help.