0 Replies Latest reply on Dec 17, 2013 11:41 PM by springhibernatetutorials

    Problem with distributed cluster cache

    springhibernatetutorials

      I have written a sample code for distributed clustered caching.please let me know this is correct and how to test this program without any server.

       

      I have created a simpleCacheExample class and created instance for EmbeddedCacheManger.From there Iam getting cache.

       

      public class SimpleCacheExample {

       

          public static void main(String[] args) {

            

              EmbeddedCacheManager ecm=createCacheManagerProgramatically();

              Cache cache=ecm.getCache();

            

            

            

                  if(!cache.isEmpty()){

                      System.out.println("cache hit");

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

                  }

                  else

                  {

                      System.out.println("cache miss putting element in cache");

                      cache.put(1, "testing");

                    

                  }

                

            

                

            

                

       

          }

          private static EmbeddedCacheManager createCacheManagerProgramatically() {

                return new DefaultCacheManager(

                      GlobalConfigurationBuilder.defaultClusteredBuilder()

                            .transport().addProperty("configurationFile", "jgroups.xml")

                            .build(),

                      new ConfigurationBuilder()

                            .clustering().cacheMode(CacheMode.REPL_SYNC)

                            .build()

                );

             }

       

       

      }

       

      jgroups.xml

      <config xmlns="urn:org:jgroups"

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

              xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-3.4.xsd">

         <UDP

               mcast_addr="${jgroups.udp.mcast_addr:228.6.7.8}"

               mcast_port="${jgroups.udp.mcast_port:46655}"

               tos="8"

               ucast_recv_buf_size="20m"

               ucast_send_buf_size="640k"

               mcast_recv_buf_size="25m"

               mcast_send_buf_size="640k"

               loopback="true"

               max_bundle_size="64k"

               ip_ttl="${jgroups.udp.ip_ttl:2}"

               enable_diagnostics="false"

       

               thread_naming_pattern="pl"

       

               thread_pool.enabled="true"

               thread_pool.min_threads="2"

               thread_pool.max_threads="30"

               thread_pool.keep_alive_time="5000"

               thread_pool.queue_enabled="false"

               thread_pool.queue_max_size="100"

               thread_pool.rejection_policy="Discard"

       

               oob_thread_pool.enabled="true"

               oob_thread_pool.min_threads="2"

               oob_thread_pool.max_threads="30"

               oob_thread_pool.keep_alive_time="5000"

               oob_thread_pool.queue_enabled="false"

               oob_thread_pool.queue_max_size="100"

               oob_thread_pool.rejection_policy="Discard"

               />

       

         <PING timeout="3000" num_initial_members="2"/>

         <MERGE2 max_interval="30000" min_interval="10000"/>

         <FD_SOCK/>

         <FD_ALL/>

         <BARRIER />

         <pbcast.NAKACK2

                 use_mcast_xmit="true"

                 discard_delivered_msgs="true"/>

         <UNICAST3/>

         <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="1000000"/>

         <pbcast.GMS print_local_addr="false" join_timeout="3000" view_bundling="true"/>

         <UFC max_credits="2m" min_threshold="0.40"/>

         <MFC max_credits="2m" min_threshold="0.40"/>

         <FRAG2 frag_size="60k"  />

      </config>

       

       

      Do i need to do any extra configuration apart from this for above example