1 22 package org.jboss.test.aop.bean; 23 24 import org.jboss.aspects.versioned.DistributedTxCache; 25 import org.jboss.logging.Logger; 26 import org.jboss.system.ServiceMBeanSupport; 27 import org.jboss.util.id.GUID; 28 29 import javax.management.MBeanRegistration ; 30 import javax.management.MBeanServer ; 31 import javax.management.ObjectName ; 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 41 public class CacheTester 42 extends ServiceMBeanSupport 43 implements CacheTesterMBean, MBeanRegistration 44 { 45 static Logger log = Logger.getLogger(CacheTester.class); 48 MBeanServer m_mbeanServer; 49 DistributedTxCache cache; 50 GUID vmid = new GUID(); 51 53 public CacheTester() 55 {} 56 57 59 public ObjectName preRegister(MBeanServer server, ObjectName name) 61 throws Exception 62 { 63 m_mbeanServer = server; 64 return name; 65 } 66 67 public void postRegister(Boolean registrationDone) 68 {} 69 public void preDeregister() throws Exception 70 {} 71 public void postDeregister() 72 {} 73 74 protected void createService() 75 throws Exception 76 { 77 cache = new DistributedTxCache(10, 5000, "Test"); 78 cache.create(); 79 } 80 81 protected void startService() 82 throws Exception 83 { 84 cache.start(); 85 Thread.sleep(5000); 86 Person person = (Person)cache.get("Bill"); 87 if (person != null) 88 { 89 log.info("Bill found in cache, no need to create"); 90 log.info(person.getName() + " is " + person.getAge() + " years old"); 91 log.info("lives at : " + person.getAddress().getStreet()); 92 log.info(person.getAddress().getCity() + ", " + person.getAddress().getState()); 93 log.info("hobbies: "); 94 Iterator it = person.getHobbies().iterator(); 95 while (it.hasNext()) 96 { 97 log.info(it.next()); 98 } 99 } 100 else 101 { 102 log.info("inserting stuff"); 103 Address address = new Address("Marlborough Street", "Boston", "MA"); 104 person = new Person("Bill", 32, address); 105 person.addHobby("Football"); 106 person.addHobby("Basketball"); 107 cache.insert("Bill", person); 108 } 109 } 110 111 protected void stopService() { } 112 113 public String getVMID() 114 { 115 return vmid.toString(); 116 } 117 118 public int getAge(String key) 119 { 120 Person person = (Person)cache.get(key); 121 return person.getAge(); 122 } 123 124 public void setAge(String key, int value) 125 { 126 Person person = (Person)cache.get(key); 127 person.setAge(value); 128 } 129 130 public List getHobbies(String key) 131 { 132 Person person = (Person)cache.get(key); 133 return new ArrayList (person.getHobbies()); 134 } 135 136 public void addHobby(String key, String hobby) 137 { 138 Person person = (Person)cache.get(key); 139 person.addHobby(hobby); 140 } 141 142 public String getCity(String key) 143 { 144 Person person = (Person)cache.get(key); 145 return person.getAddress().getCity(); 146 } 147 148 public void setCity(String key, String city) 149 { 150 Person person = (Person)cache.get(key); 151 person.getAddress().setCity(city); 152 } 153 154 155 } 157 158 | Popular Tags |