3 Replies Latest reply on Mar 12, 2010 9:59 AM by Manik Surtani

    Beginner needs help

    ermes martino Newbie

      Dear all,

      We are running an application which makes an intensive use of cache- at the moment we've solved some memory issues switching to a cluster, yet we cannot afford to have nodes larger then 2 Giga so we are planning to turn to a grid solution like Infinispan which could be terribly useful for our case.

      I've read the Api docs and some docs and I'd like to try sharing data between two JVM.

       

      In the first JVM one I've created an instance of the DefaultCacheManager and added some data:

       

      CacheManager manager = new DefaultCacheManager();

      Cache cache = manager.getCache();

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

       

      Now I'd like to access this Cache from a second JVM. How can I do it ?

      Creating another CacheManager seems not the right thing to do it.....

       

      CacheManager manager = new DefaultCacheManager();

      Cache cache = manager.getCache();

      Object obj = cache.get(key);

       

      As a matter of fact this returns null. I thought that when a Cache is created, it would automatically scan for other host in the grid and share the content of the Cache using the default JGroups protocol.

      Do I need to store the CacheManager in an external location like JNDI ? or do I need to start the CacheManager in Cluster mode to get it working?

       

      Actually the only feature we would need is partitioning the load on several hosts so we would avoid using a cluster if this can be done with plain JVMs instances..........

      Thanks a lot for your attention,

      Ermes

       

        • 1. Re: Beginner needs help
          Mircea Markus Master

          I think new DefaultCacheManager() will build a local cache, that is not cluster enabled.I suggest starting with this: http://community.jboss.org/wiki/5minutetutorialonInfinispan for a quick setup of the cluster. For more detailed documentation go here: http://community.jboss.org/wiki/infinispan

          • 2. Re: Beginner needs help
            ermes martino Newbie

            Hi, thanks for your reply.

            I've changed the CacheManager to use the Cluster Configuration
             
                     GlobalConfiguration gc = GlobalConfiguration.getClusteredDefault();
                             Configuration c = new Configuration();
                             c.setCacheMode(Configuration.CacheMode.REPL_SYNC);

                             CacheManager manager = new DefaultCacheManager(gc, c);
                 }

             

            As a matter of fact I can see on both JVM the logs :

             

            INFO: Received new cluster view: [ERMES-NB-29342|1] [ERMES-NB-29342, ERMES
            -NB-15091]
            12-mar-2010 15.38.32 org.infinispan.util.logging.AbstractLogImpl info
            INFO: Cache local address is ERMES-NB-15091, physical addresses are [10.13.1
            43.73:3166]

             

            However when I add some data from one cluster member, I cannot see anything on the other cluster member.

             

                 public Object getValue(String key) {
                    Cache cache = manager.getCache();
                    return cache.get(key);

                 }

             

            From a further test I discovered that if I set Cache as a global variable the data is replicated CORRECTLY.

                 cache = manager.getCache();

                 . . . . . .  

                 public Object getValue(String key) {
                       return cache.get(key);

                 }

            So my last question: is it safe to declare Cache as global variable ?

            Thanks alot

            Ermes

            • 3. Re: Beginner needs help
              Manik Surtani Master

              dimar1975 wrote:

              So my last question: is it safe to declare Cache as global variable ?

              Thanks alot

              Ermes

              Yes.