1 8 9 package test.javax.management.support; 10 11 import javax.management.InstanceNotFoundException ; 12 import javax.management.MBeanOperationInfo ; 13 import javax.management.MBeanParameterInfo ; 14 import javax.management.MBeanRegistration ; 15 import javax.management.MBeanServer ; 16 import javax.management.Notification ; 17 import javax.management.NotificationListener ; 18 import javax.management.ObjectName ; 19 20 import mx4j.AbstractDynamicMBean; 21 import test.MutableBoolean; 22 import test.MutableObject; 23 24 27 public class RegistrationSupport 28 { 29 public interface NullObjectNameMBean 30 { 31 } 32 33 public static class NullObjectName implements NullObjectNameMBean, MBeanRegistration  34 { 35 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  36 { 37 return null; 38 } 39 40 public void postRegister(Boolean registrationDone) 41 { 42 } 43 44 public void preDeregister() throws Exception  45 { 46 } 47 48 public void postDeregister() 49 { 50 } 51 } 52 53 public interface PreRegisterExceptionMBean 54 { 55 } 56 57 public static class PreRegisterException implements PreRegisterExceptionMBean, MBeanRegistration  58 { 59 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  60 { 61 throw new Exception (); 62 } 63 64 public void postRegister(Boolean registrationDone) 65 { 66 } 67 68 public void preDeregister() throws Exception  69 { 70 } 71 72 public void postDeregister() 73 { 74 } 75 } 76 77 public interface PostRegisterExceptionMBean 78 { 79 } 80 81 public static class PostRegisterException implements PostRegisterExceptionMBean, MBeanRegistration  82 { 83 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  84 { 85 return name; 86 } 87 88 public void postRegister(Boolean registrationDone) 89 { 90 throw new RuntimeException (); 91 } 92 93 public void preDeregister() throws Exception  94 { 95 } 96 97 public void postDeregister() 98 { 99 } 100 } 101 102 public interface PreDeregisterExceptionMBean 103 { 104 } 105 106 public static class PreDeregisterException implements PreDeregisterExceptionMBean, MBeanRegistration  107 { 108 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  109 { 110 return name; 111 } 112 113 public void postRegister(Boolean registrationDone) 114 { 115 } 116 117 public void preDeregister() throws Exception  118 { 119 throw new Exception (); 120 } 121 122 public void postDeregister() 123 { 124 } 125 } 126 127 public interface PostDeregisterExceptionMBean 128 { 129 } 130 131 public static class PostDeregisterException implements PostDeregisterExceptionMBean, MBeanRegistration  132 { 133 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  134 { 135 return name; 136 } 137 138 public void postRegister(Boolean registrationDone) 139 { 140 } 141 142 public void preDeregister() throws Exception  143 { 144 } 145 146 public void postDeregister() 147 { 148 throw new RuntimeException (); 149 } 150 } 151 152 public interface EmptyMBean 153 { 154 } 155 156 public static class Empty implements EmptyMBean, MBeanRegistration  157 { 158 private MutableBoolean m_bool1; 159 private MutableBoolean m_bool2; 160 161 public Empty(MutableBoolean bool1, MutableBoolean bool2) 162 { 163 m_bool1 = bool1; 164 m_bool2 = bool2; 165 } 166 167 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  168 { 169 return name; 170 } 171 172 public void postRegister(Boolean registrationDone) 173 { 174 m_bool1.set(registrationDone.booleanValue()); 175 } 176 177 public void preDeregister() throws Exception  178 { 179 m_bool1.set(false); 180 } 181 182 public void postDeregister() 183 { 184 m_bool2.set(false); 185 } 186 } 187 188 public interface EmptyDuplicateMBean 189 { 190 } 191 192 public static class EmptyDuplicate implements EmptyDuplicateMBean, MBeanRegistration  193 { 194 private ObjectName m_name; 195 private MutableBoolean m_bool1; 196 197 public EmptyDuplicate(ObjectName name, MutableBoolean bool1) 198 { 199 m_name = name; 200 m_bool1 = bool1; 201 } 202 203 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  204 { 205 return m_name; 206 } 207 208 public void postRegister(Boolean registrationDone) 209 { 210 m_bool1.set(registrationDone.booleanValue()); 211 } 212 213 public void preDeregister() throws Exception  214 { 215 } 216 217 public void postDeregister() 218 { 219 } 220 } 221 222 public interface StdMBean 223 { 224 public void method(); 225 } 226 227 public static class Std implements StdMBean, MBeanRegistration  228 { 229 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  230 { 231 return name; 232 } 233 234 public void postRegister(Boolean registrationDone) 235 { 236 } 237 238 public void preDeregister() throws Exception  239 { 240 } 241 242 public void postDeregister() 243 { 244 } 245 246 public void method() 247 { 248 } 249 } 250 251 public static class Dyn extends AbstractDynamicMBean implements MBeanRegistration  252 { 253 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  254 { 255 return name; 256 } 257 258 public void postRegister(Boolean registrationDone) 259 { 260 } 261 262 public void preDeregister() throws Exception  263 { 264 } 265 266 public void postDeregister() 267 { 268 } 269 270 public void method() 271 { 272 } 273 274 protected MBeanOperationInfo [] createMBeanOperationInfo() 275 { 276 return new MBeanOperationInfo []{new MBeanOperationInfo (StdMBean.class.getMethods()[0].getName(), null, new MBeanParameterInfo [0], "void", MBeanOperationInfo.UNKNOWN)}; 277 } 278 } 279 280 public interface ListenerRegistrarMBean 281 { 282 } 283 284 public static class ListenerRegistrar implements ListenerRegistrarMBean, MBeanRegistration , NotificationListener  285 { 286 private final MutableObject holder; 287 private MBeanServer server; 288 private ObjectName delegate; 289 290 public ListenerRegistrar(MutableObject holder) 291 { 292 this.holder = holder; 293 } 294 295 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception  296 { 297 this.server = server; 298 delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate"); 299 return name; 300 } 301 302 public void postRegister(Boolean registrationDone) 303 { 304 try 305 { 306 server.addNotificationListener(delegate, this, null, null); 307 } 308 catch (InstanceNotFoundException x) 309 { 310 throw new Error (x.toString()); 311 } 312 } 313 314 public void preDeregister() throws Exception  315 { 316 } 317 318 public void postDeregister() 319 { 320 try 321 { 322 server.removeNotificationListener(delegate, this); 323 } 324 catch (Exception x) 325 { 326 throw new Error (x.toString()); 327 } 328 } 329 330 public void handleNotification(Notification notification, Object handback) 331 { 332 holder.set(notification); 333 } 334 } 335 } 336 | Popular Tags |