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 35 41 public class MBSUtility { 42 private MBeanServer server; 43 private ListenerRegistry listenerRegistry = null; 44 47 private static MBSUtility mejbUtility = null; 48 49 private MBSUtility(){ 50 ArrayList mbservers = (ArrayList) AccessController.doPrivileged( 51 new PrivilegedAction() { 52 public java.lang.Object run() { 53 return MBeanServerFactory.findMBeanServer(null); 54 } 55 }); 56 if (mbservers.isEmpty()) { 57 server = null; 58 } 59 else { 60 server = (MBeanServer)mbservers.get(0); 61 } 62 } 63 public static MBSUtility getMBSUtility(){ 64 if(mejbUtility == null){ 65 mejbUtility = new MBSUtility(); 66 } 67 return mejbUtility; 68 } 69 98 99 142 143 public Set queryNames(ObjectName name, QueryExp query) throws Exception { 144 176 return server.queryNames(name, query); 177 } 178 179 180 185 186 202 203 204 218 219 227 240 241 253 public Object getAttribute(ObjectName name, String attribute) throws MBeanException, 254 javax.management.AttributeNotFoundException , javax.management.InstanceNotFoundException , 255 javax.management.ReflectionException , RemoteException { 256 263 return server.getAttribute(name, attribute); 264 } 265 266 369 370 public ListenerRegistration getListenerRegistry() { 371 if (listenerRegistry == null) { 372 try { 373 listenerRegistry = new ListenerRegistry(java.net.InetAddress.getLocalHost().getHostAddress()); 374 } catch (java.net.UnknownHostException e) { 375 listenerRegistry = new ListenerRegistry(com.sun.enterprise.management.model.J2EEDomainMdl.DOMAINNAME); 376 } 377 } 378 return listenerRegistry; 379 } 380 381 388 389 391 663 665 673 public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) 674 throws javax.management.InstanceNotFoundException , RemoteException { 675 687 server.addNotificationListener(name, listener, filter, handback); 688 } 689 690 699 public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) 700 throws javax.management.InstanceNotFoundException , RemoteException { 701 server.addNotificationListener(name, listener, filter, handback); 702 } 703 704 712 public void removeNotificationListener(ObjectName name, NotificationListener listener) 713 throws javax.management.InstanceNotFoundException , javax.management.ListenerNotFoundException , RemoteException { 714 724 725 server.removeNotificationListener(name, listener); 726 } 727 728 736 public void removeNotificationListener(ObjectName name, ObjectName listener) throws javax.management.InstanceNotFoundException , 737 javax.management.ListenerNotFoundException , RemoteException { 738 server.removeNotificationListener(name, listener); 739 } 740 741 753 } 754 | Popular Tags |