1 23 24 29 package com.sun.cli.jmx.util; 30 31 import javax.management.*; 32 import java.io.IOException ; 33 import java.util.Set ; 34 35 36 42 public class MBeanServerConnection_Hook implements MBeanServerConnection 43 { 44 private final MBeanServerConnection mConn; 45 46 63 public interface Hook 64 { 65 long preHook( String methodName ); 66 long preHook( String nmethodName, Object [] args ); 67 void postHook( long id, String methodName ); 68 void postHook( long id, String methodName, Object [] args ); 69 void postHook( long id, String methodName, Object [] args, Object result ); 70 ObjectName nameHook( long id, ObjectName methodName ) throws IOException ; 71 } 72 73 static public class HookImpl 74 implements Hook 75 { 76 public static final HookImpl HOOK = new HookImpl(); 77 78 long mID; 79 public 80 HookImpl() 81 { 82 mID = 0; 83 } 84 85 synchronized long 86 getNewID() 87 { 88 return( mID++ ); 89 } 90 91 public long preHook( String methodName ) { return( getNewID() ); } 92 public long preHook( String methodName, Object [] args ) { return( getNewID() ); } 93 public void postHook( long id, String methodName ) {} 94 public void postHook( long id, String methodName, Object [] args ) {} 95 public void postHook( long id, String methodName, Object [] args, Object result ) {} 96 public ObjectName nameHook( long id, ObjectName methodName ) throws IOException { return( methodName ); } 97 } 98 99 Hook 100 getHook() 101 { 102 return( HookImpl.HOOK ); 103 } 104 105 public 106 MBeanServerConnection_Hook( 107 MBeanServerConnection conn ) 108 { 109 mConn = conn; 110 111 assert( getConn() != null ); 112 113 } 114 115 MBeanServerConnection 116 getConn() 117 { 118 return( mConn ); 119 } 120 121 long 122 callPreHook( String name, Object [] args ) 123 { 124 return( getHook().preHook( name, args ) ); 125 } 126 127 long 128 callPreHook( String name ) 129 { 130 return( getHook().preHook( name, null ) ); 131 } 132 133 void 134 callPostHook( long id, String name, Object [] args, Object result ) 135 { 136 getHook().postHook( id, name, args, result ); 137 } 138 139 void 140 callPostHook( long id, String name, Object [] args ) 141 { 142 getHook().postHook( id, name, args ); 143 } 144 145 void 146 callPostHook( long id, String name ) 147 { 148 getHook().postHook( id, name ); 149 } 150 151 ObjectName 152 callNameHook( long id, ObjectName objectName ) 153 throws IOException 154 { 155 return( getHook().nameHook( id, objectName ) ); 156 } 157 158 public ObjectInstance createMBean(String className, ObjectName name) 159 throws ReflectionException, InstanceAlreadyExistsException, 160 MBeanRegistrationException, MBeanException, 161 NotCompliantMBeanException, IOException 162 { 163 final Object [] args = new Object [] { className, name }; 164 165 final long id = callPreHook( "createMBean", args ); 166 167 final ObjectInstance result = getConn().createMBean( className, name ); 168 169 callPostHook( id, "createMBean", args, result ); 170 171 return( result ); 172 } 173 174 public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) 175 throws ReflectionException, InstanceAlreadyExistsException, 176 MBeanRegistrationException, MBeanException, 177 NotCompliantMBeanException, InstanceNotFoundException, 178 IOException 179 { 180 final Object [] args = new Object [] { className, name, loaderName }; 181 final long id = callPreHook( "createMBean", args ); 182 183 final ObjectInstance result = getConn().createMBean( className, name, loaderName ); 184 185 callPostHook( id, "createMBean", args, result ); 186 187 return( result ); 188 } 189 190 191 192 public ObjectInstance createMBean(String className, ObjectName name, 193 Object params[], String signature[]) 194 throws ReflectionException, InstanceAlreadyExistsException, 195 MBeanRegistrationException, MBeanException, 196 NotCompliantMBeanException, IOException 197 { 198 final Object [] args = new Object [] { className, name, params, signature }; 199 final long id = callPreHook( "createMBean", args ); 200 201 final ObjectInstance result = getConn().createMBean( className, name, params, signature ); 202 203 callPostHook( id, "createMBean", args, result ); 204 205 return( result ); 206 } 207 208 209 public ObjectInstance createMBean(String className, ObjectName name, 210 ObjectName loaderName, Object params[], 211 String signature[]) 212 throws ReflectionException, InstanceAlreadyExistsException, 213 MBeanRegistrationException, MBeanException, 214 NotCompliantMBeanException, InstanceNotFoundException, 215 IOException 216 { 217 final Object [] args = new Object [] { className, name, loaderName, params, signature }; 218 final long id = callPreHook( "createMBean", args ); 219 220 final ObjectInstance result = 221 getConn().createMBean( className, name, loaderName, params, signature); 222 223 callPostHook( id, "createMBean", args, result ); 224 225 return( result ); 226 } 227 228 229 public void unregisterMBean(ObjectName name) 230 throws InstanceNotFoundException, MBeanRegistrationException, 231 IOException 232 { 233 final Object [] args = new Object [] { name }; 234 final long id = callPreHook( "unregisterMBean", args ); 235 236 getConn().unregisterMBean( callNameHook( id, name ) ); 237 238 callPostHook( id, "unregisterMBean", args ); 239 } 240 241 242 public ObjectInstance getObjectInstance(ObjectName name) 243 throws InstanceNotFoundException, IOException 244 { 245 final Object [] args = new Object [] { name }; 246 final long id = callPreHook( "getObjectInstance", args ); 247 248 final ObjectInstance result = getConn().getObjectInstance( callNameHook( id, name ) ); 249 250 callPostHook( id, "getObjectInstance", args, result ); 251 252 return( result ); 253 } 254 255 256 public Set queryMBeans(ObjectName name, QueryExp query) 257 throws IOException 258 { 259 final Object [] args = new Object [] { name, query }; 260 final long id = callPreHook( "queryMBeans", args ); 261 262 final Set result = getConn().queryMBeans( name, query ); 263 264 callPostHook( id, "queryMBeans", args, result ); 265 266 return( result ); 267 } 268 269 270 public Set queryNames(ObjectName name, QueryExp query) 271 throws IOException 272 { 273 final Object [] args = new Object [] { name, query }; 274 final long id = callPreHook( "queryNames", args ); 275 276 final Set result = getConn().queryMBeans( name, query ); 277 278 callPostHook( id, "queryNames", args, result ); 279 280 return( result ); 281 } 282 283 284 285 286 public boolean isRegistered(ObjectName name) 287 throws IOException 288 { 289 final Object [] args = new Object [] { name }; 290 final long id = callPreHook( "isRegistered", args ); 291 292 boolean registered = false; 293 294 registered = getConn().isRegistered( callNameHook( id, name ) ); 295 296 callPostHook( id, "isRegistered", args, registered ? Boolean.TRUE : Boolean.FALSE ); 297 298 return( registered ); 299 } 300 301 302 303 public Integer getMBeanCount() 304 throws IOException 305 { 306 final long id = callPreHook( "getMBeanCount", null ); 307 308 final Integer result = getConn().getMBeanCount( ); 309 310 callPostHook( id, "getMBeanCount", null, result ); 311 312 return( result ); 313 } 314 315 316 public Object getAttribute(ObjectName name, String attribute) 317 throws MBeanException, AttributeNotFoundException, 318 InstanceNotFoundException, ReflectionException, 319 IOException 320 { 321 final Object [] args = new Object [] { name, attribute }; 322 final long id = callPreHook( "getAttribute", args ); 323 324 final Object result = getConn().getAttribute( callNameHook( id, name ), attribute ); 325 326 callPostHook( id, "getAttribute", args, result ); 327 328 return( result ); 329 } 330 331 332 333 public AttributeList getAttributes(ObjectName name, String [] attributes) 334 throws InstanceNotFoundException, ReflectionException, 335 IOException 336 { 337 final Object [] args = new Object [] { name, attributes }; 338 final long id = callPreHook( "getAttributes", args ); 339 340 final AttributeList result = getConn().getAttributes( callNameHook( id, name ), attributes ); 341 342 callPostHook( id, "getAttributes", args, result ); 343 344 return( result ); 345 } 346 347 348 public void setAttribute(ObjectName name, Attribute attribute) 349 throws InstanceNotFoundException, AttributeNotFoundException, 350 InvalidAttributeValueException, MBeanException, 351 ReflectionException, IOException 352 { 353 final Object [] args = new Object [] { name, attribute }; 354 final long id = callPreHook( "setAttribute", args ); 355 356 getConn().setAttribute( callNameHook( id, name ), attribute ); 357 358 callPostHook( id, "setAttribute", args ); 359 } 360 361 362 363 364 public AttributeList setAttributes(ObjectName name, AttributeList attributes) 365 throws InstanceNotFoundException, ReflectionException, IOException 366 { 367 final Object [] args = new Object [] { name, attributes }; 368 final long id = callPreHook( "setAttributes", args ); 369 370 final AttributeList result = getConn().setAttributes( callNameHook( id, name ), attributes ); 371 372 callPostHook( id, "setAttributes", args ); 373 374 return( result ); 375 } 376 377 378 public Object invoke(ObjectName name, String operationName, 379 Object params[], String signature[]) 380 throws InstanceNotFoundException, MBeanException, 381 ReflectionException, IOException 382 { 383 final Object [] args = new Object [] { name, operationName, params, signature }; 384 final long id = callPreHook( "invoke", args ); 385 386 final Object result = getConn().invoke( callNameHook( id, name ), operationName, params, signature); 387 388 callPostHook( id, "invoke", args ); 389 return( result ); 390 } 391 392 393 394 395 public String getDefaultDomain() 396 throws IOException 397 { 398 final long id = callPreHook( "getDefaultDomain" ); 399 400 final String result = getConn().getDefaultDomain(); 401 402 callPostHook( id, "getDefaultDomain" ); 403 404 return( result ); 405 } 406 407 408 public String [] getDomains() 409 throws IOException 410 { 411 final long id = callPreHook( "getDomains" ); 412 413 final String [] result = getConn().getDomains( ); 414 415 callPostHook( id, "getDefaultDomain", result ); 416 417 return( result ); 418 } 419 420 421 public void addNotificationListener(ObjectName name, 422 NotificationListener listener, 423 NotificationFilter filter, 424 Object handback) 425 throws InstanceNotFoundException, IOException 426 { 427 final Object [] args = new Object [] { name, listener, filter, handback }; 428 final long id = callPreHook( "addNotificationListener", args ); 429 430 getConn().addNotificationListener( callNameHook( id, name ), listener, filter, handback ); 431 432 callPostHook( id, "addNotificationListener", args ); 433 } 434 435 436 437 public void addNotificationListener(ObjectName name, 438 ObjectName listener, 439 NotificationFilter filter, 440 Object handback) 441 throws InstanceNotFoundException, IOException 442 { 443 final Object [] args = new Object [] { name, listener, filter, handback }; 444 final long id = callPreHook( "addNotificationListener", args ); 445 446 getConn().addNotificationListener( callNameHook( id, name ), listener, filter, handback ); 447 448 callPostHook( id, "addNotificationListener", args ); 449 } 450 451 452 453 public void removeNotificationListener(ObjectName name, 454 ObjectName listener) 455 throws InstanceNotFoundException, ListenerNotFoundException, 456 IOException 457 { 458 final Object [] args = new Object [] { listener }; 459 final long id = callPreHook( "removeNotificationListener", args ); 460 461 getConn().removeNotificationListener( callNameHook( id, name ), listener ); 462 463 callPostHook( id, "removeNotificationListener", args ); 464 } 465 466 467 public void removeNotificationListener(ObjectName name, 468 ObjectName listener, 469 NotificationFilter filter, 470 Object handback) 471 throws InstanceNotFoundException, ListenerNotFoundException, 472 IOException 473 { 474 final Object [] args = new Object [] { name, listener, filter, handback }; 475 final long id = callPreHook( "removeNotificationListener", args ); 476 477 getConn().removeNotificationListener( callNameHook( id, name ), listener, filter, handback ); 478 479 callPostHook( id, "removeNotificationListener", args ); 480 } 481 482 483 484 public void removeNotificationListener(ObjectName name, 485 NotificationListener listener) 486 throws InstanceNotFoundException, ListenerNotFoundException, 487 IOException 488 { 489 final Object [] args = new Object [] { name, listener }; 490 final long id = callPreHook( "removeNotificationListener", args ); 491 492 getConn().removeNotificationListener( callNameHook( id, name ), listener ); 493 494 callPostHook( id, "removeNotificationListener", args ); 495 } 496 497 498 public void removeNotificationListener(ObjectName name, 499 NotificationListener listener, 500 NotificationFilter filter, 501 Object handback) 502 throws InstanceNotFoundException, ListenerNotFoundException, 503 IOException 504 { 505 final Object [] args = new Object [] { name, listener, filter, handback }; 506 final long id = callPreHook( "removeNotificationListener", args ); 507 508 getConn().removeNotificationListener( callNameHook( id, name ), listener, filter, handback ); 509 510 callPostHook( id, "removeNotificationListener", args ); 511 } 512 513 514 public MBeanInfo getMBeanInfo(ObjectName name) 515 throws InstanceNotFoundException, IntrospectionException, 516 ReflectionException, IOException 517 { 518 final Object [] args = new Object [] { name }; 519 final long id = callPreHook( "getMBeanInfo", args ); 520 521 final MBeanInfo result = getConn().getMBeanInfo( callNameHook( id, name ) ); 522 523 callPostHook( id, "getMBeanInfo", args ); 524 525 return( result ); 526 } 527 528 529 530 public boolean isInstanceOf(ObjectName name, String className) 531 throws InstanceNotFoundException, IOException 532 { 533 final Object [] args = new Object [] { name, className }; 534 final long id = callPreHook( "isInstanceOf", args ); 535 536 final boolean isInstance = getConn().isInstanceOf( callNameHook( id, name ), className ); 537 538 callPostHook( id, "isInstanceOf", args, isInstance ? Boolean.TRUE : Boolean.FALSE ); 539 540 return( isInstance ); 541 } 542 543 }; 544 545 | Popular Tags |