1 7 package org.jboss.cache.loader; 8 9 import org.jgroups.Address; 10 import org.jgroups.View; 11 import org.jboss.cache.TreeCacheListener; 12 import org.jboss.cache.Fqn; 13 import org.jboss.cache.TreeCache; 14 import org.jboss.logging.Logger; 15 16 import java.util.*; 17 18 30 public class SharedStoreCacheLoader implements TreeCacheListener, CacheLoader { 31 CacheLoader loader=null; 32 Address local_addr=null; 33 boolean active=true; Logger log=Logger.getLogger(getClass()); 35 TreeCache cache=null; 36 37 38 public SharedStoreCacheLoader(CacheLoader loader, Address local_addr, boolean coordinator) { 39 this.loader=loader; 40 this.local_addr=local_addr; 41 this.active=coordinator; 42 } 43 44 45 46 47 public void nodeCreated(Fqn fqn) {} 48 public void nodeRemoved(Fqn fqn) {} 49 public void nodeLoaded(Fqn fqn) {} 50 public void nodeEvicted(Fqn fqn) {} 51 public void nodeModified(Fqn fqn) {} 52 public void nodeVisited(Fqn fqn) {} 53 public void cacheStarted(TreeCache cache) {} 54 public void cacheStopped(TreeCache cache) {} 55 56 public void viewChange(View new_view) { 57 boolean tmp=active; 58 if(new_view != null && local_addr != null) { 59 Vector mbrs=new_view.getMembers(); 60 if(mbrs != null && mbrs.size() > 0 && local_addr.equals(mbrs.firstElement())) { 61 tmp=true; 62 } 63 else { 64 tmp=false; 65 } 66 } 67 if(active != tmp) { 68 active=tmp; 69 log.info("changed mode: active=" + active); 70 } 71 } 72 73 74 public void setConfig(Properties props) { 75 loader.setConfig(props); 76 } 77 78 public void setCache(TreeCache c) { 79 this.cache=c; 80 loader.setCache(c); 81 } 82 83 public Set getChildrenNames(Fqn fqn) throws Exception { 84 return loader.getChildrenNames(fqn); 85 } 86 87 public Object get(Fqn name, Object key) throws Exception { 88 return loader.get(name, key); 89 } 90 91 public Map get(Fqn name) throws Exception { 92 return loader.get(name); 93 } 94 95 public boolean exists(Fqn name) throws Exception { 96 return loader.exists(name); 97 } 98 99 public Object put(Fqn name, Object key, Object value) throws Exception { 100 if(active) 101 return loader.put(name, key, value); 102 else 103 return null; 104 } 105 106 public void put(Fqn name, Map attributes) throws Exception { 107 if(active) 108 loader.put(name, attributes); 109 } 110 111 public void put(List modifications) throws Exception { 112 if(active) 113 loader.put(modifications); 114 } 115 116 public Object remove(Fqn name, Object key) throws Exception { 117 if(active) 118 return loader.remove(name, key); 119 return null; 120 } 121 122 public void remove(Fqn name) throws Exception { 123 if(active) 124 loader.remove(name); 125 } 126 127 public void removeData(Fqn name) throws Exception { 128 if(active) 129 loader.removeData(name); 130 } 131 132 public void prepare(Object tx, List modifications, boolean one_phase) throws Exception { 133 if(active) 134 loader.prepare(tx, modifications, one_phase); 135 } 136 137 public void commit(Object tx) throws Exception { 138 if(active) 139 loader.commit(tx); 140 } 141 142 public void rollback(Object tx) { 143 if(active) 144 loader.rollback(tx); 145 } 146 147 public byte[] loadEntireState() throws Exception { 148 return loader.loadEntireState(); 149 } 150 151 public void storeEntireState(byte[] state) throws Exception { 152 if(active) 153 loader.storeEntireState(state); 154 } 155 156 public void create() throws Exception { 157 loader.create(); 158 } 159 160 public void start() throws Exception { 161 loader.start(); 162 } 163 164 public void stop() { 165 loader.stop(); 166 } 167 168 public void destroy() { 169 loader.destroy(); 170 } 171 172 } 173 | Popular Tags |