0 Replies Latest reply on Nov 6, 2008 6:33 AM by daniel jarrett

    Steps to setting up a pojo cache

    daniel jarrett Newbie

      I'm wondering if anyone can help guide me through the steps to setting up a basic pojo cache. Think "pojo cache for dummies".. the dummy being myself.


      My steps so far:

      I'm using the "all" server in my jboss 4.2.2 AS. So I guess I'm using JbossCache 1.?.

      Note that I haven't included any extra JbossCache libraries other than the ones already provided by the application server. I am also successfully using EJBEntityTreeCache as an L2 cache for my DB persistence.

      I've created an xml file as follows and placed it in my deploy directory, i basically copied it from the one that comes with the "all" setup for the ejb3 entity cache and changed it to use PojoCache

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
      
       <!-- ============================================================ -->
       <!-- Clustered entity cache config for use with JBoss Cache 1.4.x -->
       <!-- ============================================================ -->
       <mbean code="org.jboss.cache.PojoCache"
       name="jboss.cache:service=PojoCache">
      
       <depends>jboss:service=Naming</depends>
       <depends>jboss:service=TransactionManager</depends>
      
       <!-- Name of cluster. Needs to be the same on all nodes in the clusters,
       in order to find each other -->
       <attribute name="ClusterName">${jboss.partition.name:DefaultPartition}-PojoCache</attribute>
      
       <!-- Configure the TransactionManager -->
       <attribute name="TransactionManagerLookupClass">org.jboss.cache.JBossTransactionManagerLookup</attribute>
      
       <!--
       Node locking level : SERIALIZABLE
       REPEATABLE_READ (default)
       READ_COMMITTED
       READ_UNCOMMITTED
       NONE
       -->
       <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
      
       <!-- Valid modes are LOCAL
       REPL_ASYNC
       REPL_SYNC
       -->
       <attribute name="CacheMode">REPL_SYNC</attribute>
      
       <!-- Must be true if any entity deployment uses a scoped classloader -->
       <attribute name="UseRegionBasedMarshalling">true</attribute>
       <!-- Must match the value of "useRegionBasedMarshalling" -->
       <attribute name="InactiveOnStartup">true</attribute>
      
       <!--
       JGroups protocol stack config in XML format.
      
       On Windows machines, because of the media sense feature
       being broken with multicast (even after disabling media sense)
       set the UDP.loopback attribute to true
       -->
       <attribute name="ClusterConfig">
       <config>
       <UDP mcast_addr="${jboss.partition.udpGroup:230.1.2.3}"
       mcast_port="${jboss.ejb3entitypartition.mcast_port:43333}"
       tos="8"
       ucast_recv_buf_size="20000000"
       ucast_send_buf_size="640000"
       mcast_recv_buf_size="25000000"
       mcast_send_buf_size="640000"
       loopback="false"
       discard_incompatible_packets="true"
       enable_bundling="false"
       max_bundle_size="64000"
       max_bundle_timeout="30"
       use_incoming_packet_handler="true"
       use_outgoing_packet_handler="false"
       ip_ttl="${jgroups.udp.ip_ttl:2}"
       down_thread="false" up_thread="false"/>
       <PING timeout="2000"
       down_thread="false" up_thread="false" num_initial_members="3"/>
       <MERGE2 max_interval="100000"
       down_thread="false" up_thread="false" min_interval="20000"/>
       <FD_SOCK down_thread="false" up_thread="false"/>
       <FD timeout="10000" max_tries="5" down_thread="false" up_thread="false" shun="true"/>
       <VERIFY_SUSPECT timeout="1500" down_thread="false" up_thread="false"/>
       <pbcast.NAKACK max_xmit_size="60000"
       use_mcast_xmit="false" gc_lag="0"
       retransmit_timeout="300,600,1200,2400,4800"
       down_thread="false" up_thread="false"
       discard_delivered_msgs="true"/>
       <UNICAST timeout="300,600,1200,2400,3600"
       down_thread="false" up_thread="false"/>
       <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
       down_thread="false" up_thread="false"
       max_bytes="400000"/>
       <pbcast.GMS print_local_addr="true" join_timeout="3000"
       down_thread="false" up_thread="false"
       join_retry_timeout="2000" shun="true"
       view_bundling="true"/>
       <FRAG2 frag_size="60000" down_thread="false" up_thread="false"/>
       <pbcast.STATE_TRANSFER down_thread="false" up_thread="false" use_flush="false"/>
       </config>
       </attribute>
      
       <!-- The max amount of time (in milliseconds) we wait until the
       initial state (ie. the contents of the cache) are retrieved from
       existing members.
       -->
       <attribute name="InitialStateRetrievalTimeout">17500</attribute>
      
       <!-- Number of milliseconds to wait until all responses for a
       synchronous call have been received.
       -->
       <attribute name="SyncReplTimeout">17500</attribute>
      
       <!-- Max number of milliseconds to wait for a lock acquisition -->
       <attribute name="LockAcquisitionTimeout">15000</attribute>
      
       <!-- Name of the eviction policy class.
       <attribute name="EvictionPolicyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
      -->
       <!-- Specific eviction policy configurations. This is LRU -->
       <attribute name="EvictionPolicyConfig">
       <config>
       <attribute name="wakeUpIntervalSeconds">5</attribute>
       <!-- Cache wide default -->
       <region name="/_default_">
       <attribute name="maxNodes">5000</attribute>
       <attribute name="timeToLiveSeconds">1000</attribute>
       </region>
       </config>
       </attribute>
      
       </mbean>
      
      </server>





      I am using the pojo cache within my stateless session bean with the following:

      server = MBeanServerLocator.locateJBoss();
       pojoCache = (PojoCacheMBean) MBeanProxyExt.create(
       PojoCacheMBean.class, "jboss.cache:service=PojoCache",
       server);
       pojoCache.startService();
       pojoCache = new PojoCache();
       if (pojoCache == null) {
       throw new Exception("PojoCacheMBean not found. Service not bound: " + "jboss.cache:service=testPojoCache");
       }
      



      I'm entering objects into the cache and retrieving them with the following:

      cache.putObject("/session/test", session);
      Session session2 = (Session)cache.getObject("/session/test");


      The above seems to work if i set and retrieve the cache from within the same method. But when i try to "getObject" from a different method on my session bean to the one that "putObject" then it returns null.