[jboss-user] [JBossCache] - Re: Running POJOCache error

confuz do-not-reply at jboss.com
Thu Aug 3 22:05:17 EDT 2006


"ben.wang at jboss.com" wrote : 1. PojoCache does not support pure eviction. That is, it will support pure cache loader (persistency) or passivation (eviction + cacheloading).
  | 
  | 2. Yes.

For point 1 , i wrote following test code

  | package org.jboss.cache.passivation;
  | 
  | import java.io.Serializable;
  | import java.util.Properties;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.transaction.UserTransaction;
  | 
  | import org.apache.commons.logging.Log;
  | import org.apache.commons.logging.LogFactory;
  | import org.jboss.cache.CacheException;
  | import org.jboss.cache.Fqn;
  | import org.jboss.cache.PropertyConfigurator;
  | import org.jboss.cache.aop.PojoCache;
  | import org.jboss.cache.data.Address;
  | import org.jboss.cache.data.Person;
  | import org.jboss.cache.loader.CacheLoader;
  | import org.jboss.cache.loader.SamplePojo;
  | 
  | public class AOPTestPassivation1 {
  | 
  | 	PojoCache cache = null;
  | 	CacheLoader loader = null;
  | 	
  | 	/**
  | 	 * @param args
  | 	 */
  | 	public static void main(String[] args) throws Exception {
  | 		AOPTestPassivation1 tester = new AOPTestPassivation1();
  | 		tester.start();
  | 		Log log = LogFactory.getLog(AOPTestPassivation1.class);
  | 		long start = System.currentTimeMillis();
  | 		tester.test1();
  | 		System.out.println("/test/1:" + tester.cache.getObject(Fqn.fromString("/test/1")));
  | 		System.out.println("/test/2:" + tester.cache.getObject(Fqn.fromString("/test/2")));
  | 		Thread.sleep(6000);
  | 		
  | 		System.out.println("/test/3:" + tester.cache.getObject(Fqn.fromString("/test/3")));
  | 				
  | 		long end = System.currentTimeMillis();
  | 		System.out.println(end - start);
  | 		
  | 		tester.stop();
  | 	}
  | 	
  | 	
  | 	
  | 	private void test1() throws Exception{
  | 		String key = "key";
  | 		String obj = "obj";
  | 		long start = System.currentTimeMillis();
  | 		long end = System.currentTimeMillis();
  | 		for(int i = 0; i < 1; i ++){
  | 			end = System.currentTimeMillis();
  | 			System.out.println("PPP:" + i + "   Time:" + (end-start));
  | 			start = end;
  | 			for(int j = 0; j < 15; j ++){
  | 				  
  | 			      cache.putObject("/test/"+(i*1000+j), "Object" + i);
  | 			}
  | 		}
  | 	}
  | 	
  | 	
  | 	private void start() throws Exception{
  | 		cache = new PojoCache();
  | 		PropertyConfigurator pc = new PropertyConfigurator();
  | 		pc.configure(cache, "META-INF/aop-tree-service1.xml");
  | 			        
  | 		cache.createService();
  | 		cache.startService();
  | 		loader = cache.getCacheLoader();
  | 	
  | 	}
  | 	
  | 	    
  | 	private void stop() throws Exception{
  | 		cache.remove("/");
  | 	    //loader.remove(Fqn.fromString("/"));
  | 		cache.stopService();
  | 		cache.destroyService();
  | 	}
  | 	
  | }
  | 

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <!-- ===================================================================== -->
  | <!--                                                                       -->
  | <!--  Sample TreeCache Service Configuration                               -->
  | <!--                                                                       -->
  | <!-- ===================================================================== -->
  | 
  | <server>
  | 
  |     <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar"/>
  | 
  | 
  |     <!-- ==================================================================== -->
  |     <!-- Defines TreeCache configuration                                      -->
  |     <!-- ==================================================================== -->
  | 
  |     <mbean code="org.jboss.cache.aop.PojoCache"
  |         name="jboss.cache:service=testTreeCache">
  | 
  |         <depends>jboss:service=Naming</depends>
  |         <depends>jboss:service=TransactionManager</depends>
  | 
  |         <attribute name="TransactionManagerLookupClass">org.jboss.cache.DummyTransactionManagerLookup</attribute>
  | 
  |         <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
  | 
  |         <attribute name="CacheMode">REPL_SYNC</attribute>
  | 
  |         <attribute name="ClusterName">TreeCache-Cluster</attribute>
  | 
  |         <attribute name="InitialStateRetrievalTimeout">20000</attribute>
  | 
  |         <attribute name="SyncReplTimeout">15000</attribute>
  | 
  |         <attribute name="LockAcquisitionTimeout">10000</attribute>
  | 
  |         <attribute name="EvictionPolicyClass">org.jboss.cache.aop.eviction.AopLRUPolicy</attribute>
  | 
  |       <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>
  |             <region name="/aop">
  |                 <attribute name="maxNodes">5</attribute>
  |                 <attribute name="timeToLiveSeconds">4</attribute>
  |             </region>
  |             <region name="/pojo">
  |                 <attribute name="maxNodes">100</attribute>
  |                 <attribute name="timeToLiveSeconds">4</attribute>
  |             </region>
  |             <region name="/test">
  |                 <attribute name="maxNodes">10</attribute>
  |                 <attribute name="timeToLiveSeconds">0</attribute>
  |             </region>
  |          </config>
  |       </attribute>
  |       
  |       
  |         <attribute name="CacheLoaderConfiguration">
  |             <config>
  |                 <passivation>true</passivation>
  |                 
  | 	 			<shared>false</shared>
  |                 
  |                 <cacheloader>
  |                     <class>org.jboss.cache.loader.bdbje.BdbjeCacheLoader</class>
  |                      <properties>
  |                         location=c:/tmp/filetore1
  |                     </properties>
  |                     <async>false</async>
  |                     
  |                     <fetchPersistentState>false</fetchPersistentState>
  |                     <ignoreModifications>false</ignoreModifications>
  |                      <purgeOnStartup>false</purgeOnStartup>
  |                 </cacheloader>
  |                 
  |          </config>
  |     </attribute>
  |         
  |     </mbean>
  | 
  | 
  | </server>
  | 

The result is different base on passivation element configureation
1. true output

  | /test/1:Object0
  | /test/2:Object0
  | /test/3:null
  | 

false output

  | /test/1:Object0
  | /test/2:Object0
  | /test/3:Object0
  | 

It seems the eviction + cacheloading works base on the passivation configuration value
I check the document for passivation 
1. <!-- if passivation is true, only the first cache loader is used; the rest are ignored -->
                false

2.To enable cache passivation/activation, you can set passivation to true. The default is false. You set it via the XML cache configuration file. The XML above shows the passivation element when configuring a cache loader. When passivation is used, only the first cache loader configured is used. All others are ignored.

how to explain the test result, thanks..

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963068#3963068

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963068



More information about the jboss-user mailing list