1 22 package org.jboss.test.cache.bean; 23 24 import java.util.Map ; 25 import java.util.Set ; 26 import java.util.Vector ; 27 28 import javax.ejb.CreateException ; 29 import javax.ejb.SessionBean ; 30 import javax.ejb.SessionContext ; 31 import javax.management.Attribute ; 32 import javax.management.MBeanServer ; 33 import javax.management.ObjectName ; 34 35 import org.jboss.cache.pojo.PojoCache; 36 import org.jboss.mx.util.MBeanProxyExt; 37 import org.jboss.mx.util.MBeanServerLocator; 38 39 52 public class TreeCacheMBeanTesterBean implements SessionBean 53 { 54 static final String OBJECT_NAME = "jboss.cache:service=testTreeCache"; 56 MBeanServer server; 57 ObjectName cacheService; 58 PojoCache cache=null; 59 60 64 public void ejbCreate() throws CreateException 65 { 66 log("Creating TreeCache ejb proxy"); 67 init(); 68 } 69 70 75 public void ejbCreate(String name) throws CreateException 76 { 77 log("I'm being created"); 78 init(name); 79 } 80 81 private void init() throws CreateException 82 { 83 init(OBJECT_NAME); 84 } 85 86 private void init(String name) throws CreateException 87 { 88 try { 89 cacheService = new ObjectName (name); 90 server = MBeanServerLocator.locate(); 91 cache=(PojoCache)server.getAttribute(new ObjectName ("jboss.cache:service=testTreeCacheAop"), 92 "PojoCache"); 93 } catch (Exception ex) { 94 throw new CreateException (ex.toString()); 95 } 96 } 97 98 public void ejbActivate() 99 { 100 } 101 102 public void ejbPassivate() 103 { 104 } 105 106 public void ejbRemove() 107 { 108 log("I'm being removed"); 109 } 110 111 public void setSessionContext(SessionContext ctx) 112 { 113 } 114 115 119 public Vector getMembers() throws Exception 120 { 121 throw new UnsupportedOperationException ("See FIXME in bean code"); 124 } 125 126 130 public int getCacheMode() throws Exception 131 { 132 return ((Integer ) server.getAttribute(cacheService, "CacheMode")).intValue(); 133 } 134 135 139 public void setCacheMode(int mode) throws Exception 140 { 141 server.setAttribute(cacheService, new Attribute ("CacheMode", 142 new Integer (mode))); 143 } 144 145 149 public boolean getLocking() throws Exception 150 { 151 return ((Boolean ) server.getAttribute(cacheService, "Locking")).booleanValue(); 152 } 153 154 158 public void setLocking(boolean flag) throws Exception 159 { 160 server.setAttribute(cacheService, new Attribute ("Locking", 161 new Boolean (flag))); 162 } 163 164 168 public int getLockingLevel() throws Exception 169 { 170 return ((Integer ) server.getAttribute(cacheService, "LockingLevel")).intValue(); 171 } 172 173 177 public void setLocking(int level) throws Exception 178 { 179 server.setAttribute(cacheService, new Attribute ("LockingLevel", 180 new Integer (level))); 181 } 182 183 188 public Set getKeys(String fqn) throws Exception { 189 return (Set ) server.invoke(cacheService, "getKeys", 190 new Object []{fqn}, 191 new String []{String .class.getName()}); 192 } 193 194 200 public Object get(String fqn, String key) throws Exception 201 { 202 return server.invoke(cacheService, "get", 203 new Object []{fqn, key}, 204 new String []{String .class.getName(), 205 Object .class.getName()}); 206 } 207 208 213 public boolean exists(String fqn) throws Exception 214 { 215 return ((Boolean ) server.invoke(cacheService, "exists", 216 new Object []{fqn}, 217 new String []{String .class.getName()})).booleanValue(); 218 } 219 220 226 public void put(String fqn, Map data) throws Exception 227 { 228 server.invoke(cacheService, "put", 229 new Object []{fqn, data}, 230 new String []{String .class.getName(), 231 Map .class.getName()}); 232 } 233 234 241 public void put(String fqn, String key, Object value) throws Exception 242 { 243 Object [] args = {fqn, key, value}; 244 String [] sig = {String .class.getName(), 245 Object .class.getName(), 246 Object .class.getName()}; 247 248 server.invoke(cacheService, "put", args, sig); 249 } 250 251 256 public void remove(String fqn) throws Exception 257 { 258 Object [] args = {fqn}; 259 String [] sig = {String .class.getName()}; 260 261 server.invoke(cacheService, "remove", args, sig); 262 } 263 264 265 272 public Object remove(String fqn, String key) throws Exception 273 { 274 return server.invoke(cacheService, "remove", 275 new Object []{fqn, key}, 276 new String []{String .class.getName(), 277 String .class.getName()}); 278 } 279 280 284 public void releaseAllLocks(String fqn) throws Exception 285 { 286 server.invoke(cacheService, "releaseAllLocks", 287 new Object []{fqn}, 288 new String []{String .class.getName()}); 289 } 290 291 296 public String print(String fqn) throws Exception 297 { 298 return (String ) server.invoke(cacheService, "print", 299 new Object []{fqn}, 300 new String []{String .class.getName()}); 301 } 302 303 308 public Set getChildrenNames(String fqn) throws Exception 309 { 310 return (Set ) server.invoke(cacheService, "getChildrenNames", 311 new Object []{fqn}, 312 new String []{String .class.getName()}); 313 } 314 315 319 public String printDetails() throws Exception 320 { 321 return (String ) server.invoke(cacheService, "printDetails", 322 null, 323 null); 324 } 325 326 330 public String printLockInfo() throws Exception 331 { 332 return (String ) server.invoke(cacheService, "printLockInfo", 333 null, 334 null); 335 } 336 337 private void log(String msg) 338 { 339 System.out.println("-- [" + Thread.currentThread().getName() + "]: " + msg); 340 } 341 342 } 343 | Popular Tags |