1 23 24 package com.sun.enterprise.management.agent; 25 26 import java.security.*; 27 import java.rmi.RemoteException ; 28 import java.util.*; 29 import java.io.ObjectInputStream ; 30 import javax.management.*; 32 import javax.management.j2ee.*; 33 import javax.naming.*; 34 import com.sun.enterprise.management.util.J2EEModuleUtil; 35 36 42 public class MEJBUtility { 43 private MBeanServer server; 44 private ListenerRegistry listenerRegistry = null; 45 48 private static MEJBUtility mejbUtility = null; 49 50 private MEJBUtility(){ 51 ArrayList mbservers = (ArrayList) AccessController.doPrivileged( 52 new PrivilegedAction() { 53 public java.lang.Object run() { 54 return MBeanServerFactory.findMBeanServer(null); 55 } 56 }); 57 if (mbservers.isEmpty()) { 58 server = null; 59 } 60 else { 61 server = (MBeanServer)mbservers.get(0); 62 } 63 } 64 public static MEJBUtility getMEJBUtility(){ 65 if(mejbUtility == null){ 66 mejbUtility = new MEJBUtility(); 67 } 68 return mejbUtility; 69 } 70 99 100 143 144 public Set queryNames(ObjectName name, QueryExp query) throws Exception { 145 177 return server.queryNames(name, query); 178 } 179 180 181 186 187 188 public boolean isRegistered(ObjectName name) throws Exception { 189 198 return server.isRegistered(name); 200 } 201 202 203 204 205 206 public Integer getMBeanCount() throws Exception { 207 217 return server.getMBeanCount(); 218 } 219 220 221 222 230 231 public MBeanInfo getMBeanInfo(ObjectName name) throws javax.management.InstanceNotFoundException , 232 javax.management.IntrospectionException , javax.management.ReflectionException , RemoteException { 233 242 return server.getMBeanInfo(name); 243 } 244 245 246 258 public Object getAttribute(ObjectName name, String attribute) throws MBeanException, 259 javax.management.AttributeNotFoundException , javax.management.InstanceNotFoundException , 260 javax.management.ReflectionException , RemoteException { 261 268 return server.getAttribute(name, attribute); 269 } 270 271 281 public javax.management.AttributeList getAttributes(ObjectName name, String [] attributes) 282 throws javax.management.InstanceNotFoundException , javax.management.ReflectionException , RemoteException { 283 290 return server.getAttributes(name, attributes); 291 } 292 293 306 public void setAttribute(ObjectName name, javax.management.Attribute attribute) 307 throws javax.management.InstanceNotFoundException , javax.management.AttributeNotFoundException , 308 javax.management.InvalidAttributeValueException , MBeanException, 309 javax.management.ReflectionException , RemoteException { 310 server.setAttribute(name, attribute); 311 317 } 318 319 330 public javax.management.AttributeList setAttributes(ObjectName name, javax.management.AttributeList attributes) 331 throws javax.management.InstanceNotFoundException , javax.management.ReflectionException , RemoteException { 332 return server.setAttributes(name, attributes); 333 339 340 } 341 342 355 public Object invoke(ObjectName name, String operationName, Object [] params, String [] signature) 356 throws javax.management.InstanceNotFoundException , MBeanException, 357 javax.management.ReflectionException , RemoteException { 358 return server.invoke(name, operationName, params, signature); 359 365 } 366 367 372 public String getDefaultDomain() { 373 return server.getDefaultDomain(); 374 } 375 376 379 380 public ListenerRegistration getListenerRegistry() { 381 if (listenerRegistry == null) { 382 try { 383 listenerRegistry = new ListenerRegistry(java.net.InetAddress.getLocalHost().getHostAddress()); 384 } catch (java.net.UnknownHostException e) { 385 listenerRegistry = new ListenerRegistry(J2EEModuleUtil.getDomainName()); 386 } 387 } 388 return listenerRegistry; 389 } 390 391 398 399 401 414 public Object instantiate(String className) throws javax.management.ReflectionException , MBeanException, RemoteException { 415 return server.instantiate(className); 416 } 417 418 433 public Object instantiate(String className, ObjectName loaderName) throws javax.management.ReflectionException , 434 MBeanException, javax.management.InstanceNotFoundException , RemoteException { 435 return server.instantiate(className, loaderName); 436 } 437 438 453 public Object instantiate(String className, Object [] params, String [] signature) throws javax.management.ReflectionException , 454 MBeanException, RemoteException { 455 return server.instantiate(className, params, signature); 456 } 457 458 475 public Object instantiate(String className, ObjectName loaderName, Object [] params, String [] signature) 476 throws javax.management.ReflectionException , MBeanException, 477 javax.management.InstanceNotFoundException , RemoteException { 478 return server.instantiate(className, loaderName, params, signature); 479 } 480 481 502 public ObjectInstance createMBean(String className, ObjectName name) throws javax.management.ReflectionException , 503 javax.management.InstanceAlreadyExistsException , MBeanRegistrationException, MBeanException, 504 NotCompliantMBeanException, RemoteException { 505 return server.createMBean(className, name); 506 } 507 508 531 public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) 532 throws javax.management.ReflectionException , javax.management.InstanceAlreadyExistsException , 533 MBeanRegistrationException, MBeanException, NotCompliantMBeanException, 534 javax.management.InstanceNotFoundException , RemoteException { 535 return server.createMBean(className, name, loaderName); 536 } 537 538 560 public ObjectInstance createMBean(String className, ObjectName name, Object [] params, String [] signature) 561 throws javax.management.ReflectionException , javax.management.InstanceAlreadyExistsException , 562 MBeanRegistrationException, MBeanException, NotCompliantMBeanException, RemoteException { 563 return server.createMBean(className, name, params, signature); 564 } 565 566 591 public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object [] params, String [] signature) 592 throws javax.management.ReflectionException , javax.management.InstanceAlreadyExistsException , 593 MBeanRegistrationException, MBeanException, NotCompliantMBeanException, 594 javax.management.InstanceNotFoundException , RemoteException { 595 return server.createMBean(className, name, loaderName, params, signature); 596 } 597 598 613 public ObjectInstance registerMBean(Object object, ObjectName name) throws javax.management.InstanceAlreadyExistsException , 614 MBeanRegistrationException, NotCompliantMBeanException, RemoteException { 615 return server.registerMBean(object, name); 616 } 617 618 629 public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, 630 MBeanRegistrationException, RemoteException { 631 637 server.unregisterMBean(name); 638 } 639 640 646 public ObjectInstance getObjectInstance(ObjectName name) 647 throws javax.management.InstanceNotFoundException , RemoteException { 648 return server.getObjectInstance(name); 649 } 650 651 666 public Set queryMBeans(ObjectName name, QueryExp query) throws RemoteException { 667 return server.queryMBeans(name, query); 668 } 669 670 674 676 684 public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) 685 throws javax.management.InstanceNotFoundException , RemoteException { 686 698 server.addNotificationListener(name, listener, filter, handback); 699 } 700 701 710 public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) 711 throws javax.management.InstanceNotFoundException , RemoteException { 712 server.addNotificationListener(name, listener, filter, handback); 713 } 714 715 723 public void removeNotificationListener(ObjectName name, NotificationListener listener) 724 throws javax.management.InstanceNotFoundException , javax.management.ListenerNotFoundException , RemoteException { 725 735 736 server.removeNotificationListener(name, listener); 737 } 738 739 747 public void removeNotificationListener(ObjectName name, ObjectName listener) throws javax.management.InstanceNotFoundException , 748 javax.management.ListenerNotFoundException , RemoteException { 749 server.removeNotificationListener(name, listener); 750 } 751 752 759 public boolean isInstanceOf(ObjectName name, String className) 760 throws javax.management.InstanceNotFoundException , RemoteException { 761 return server.isInstanceOf(name, className); 762 } 763 } 764 | Popular Tags |