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