1 package org.jboss.cache.tests.loader; 2 3 import org.jboss.cache.Fqn; 4 import org.jboss.cache.TreeCache; 5 6 10 public class RpcDelegatingCacheLoaderTests { 11 TreeCache cache; 12 13 14 public static void main(String [] args) { 15 boolean client=false; 16 17 for(int i=0; i < args.length; i++) { 18 String arg=args[i]; 19 if(arg.equals("client")) { 20 client=true; 21 continue; 22 } 23 if(arg.equals("server")) { 24 client=false; 25 continue; 26 } 27 help(); 28 return; 29 } 30 31 try { 32 new RpcDelegatingCacheLoaderTests().start(client); 33 } 34 catch(Exception e) { 35 e.printStackTrace(); 36 } 37 } 38 39 private static void help() { 40 System.out.println("RpcDelegatingCacheLoadeTest [client / server]"); 41 } 42 43 private void start(boolean client) throws Exception { 44 cache=new TreeCache("test-cluster", null, 3000); 45 cache.setCacheMode(TreeCache.REPL_ASYNC); 46 cache.setFetchStateOnStartup(true); 47 cache.setCacheLoaderFetchTransientState(true); 48 cache.setCacheLoaderClass("org.jboss.cache.loader.RpcDelegatingCacheLoader"); 49 cache.setCacheLoaderShared(false); 50 cache.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup"); 51 cache.startService(); 52 53 if(client == false) { 54 System.out.println("started as SERVER"); 55 System.out.println("populating the cache"); 56 cache.getTransactionManager().begin(); 57 cache.put("/a/b/c", "bela", "ban"); 58 cache.put("/1/2/3", "ben", "wang"); 59 cache.getTransactionManager().commit(); 60 System.out.println("the cache is " + cache.toString() + ", locks: " + cache.printLockInfo()); 61 62 while(true){ 63 sleep(2000); 64 cache.getTransactionManager().begin(); 65 cache.put("/x/y/z", "d", "d"); 66 cache.getTransactionManager().commit(); 67 } 68 } 69 70 System.out.println("started as CLIENT"); 71 System.out.println("initial cache (fetched from SERVER) is " + cache.printLockInfo()); 72 80 sleep(1000); 82 83 System.out.println("evicting /a and /1 locally"); 84 cache.evict(Fqn.fromString("/a/b/c")); 85 cache.evict(Fqn.fromString("/a/b")); 86 cache.evict(Fqn.fromString("/a")); 87 cache.evict(Fqn.fromString("/1/2/3")); 88 cache.evict(Fqn.fromString("/1/2")); 89 cache.evict(Fqn.fromString("/1")); 90 System.out.println("cache contents after eviction: " + cache.printLockInfo()); 91 92 System.out.println("accessing /a and /1. this will trigger a fetch from the remote SERVER"); 93 Object val=cache.get("/a/b/c", "bela"); 94 System.out.println("value is " + val); 95 96 val=cache.get("/1/2/3", "ben"); 97 System.out.println("value is " + val); 98 99 System.out.println("the cache is " + cache.toString() + ", locks: " + cache.printLockInfo()); 100 } 101 102 103 private void sleep(long time) { 104 try { 105 Thread.sleep(time); 106 } 107 catch(InterruptedException e) { 108 } 109 } 110 } 111 | Popular Tags |