1 22 package org.jboss.mx.util; 23 24 import java.util.Iterator ; 25 26 import javax.management.MBeanServer ; 27 import javax.management.MBeanServerFactory ; 28 29 43 public class MBeanServerLocator 44 { 45 46 private static MBeanServer instance = null; 47 48 51 private MBeanServerLocator() 52 { 53 } 55 56 63 public static void setJBoss(MBeanServer server) 64 { 65 synchronized (MBeanServerLocator.class) 66 { 67 instance = server; 68 } 69 } 70 71 77 public static MBeanServer locate(final String agentID) 78 { 79 MBeanServer server = (MBeanServer ) 80 MBeanServerFactory.findMBeanServer(agentID).iterator().next(); 81 82 return server; 83 } 84 85 90 public static MBeanServer locate() 91 { 92 return locate(null); 93 } 94 95 105 public static MBeanServer locateJBoss() 106 { 107 synchronized (MBeanServerLocator.class) 108 { 109 if (instance != null) 110 { 111 return instance; 112 } 113 } 114 for (Iterator i = MBeanServerFactory.findMBeanServer(null).iterator(); i.hasNext(); ) 115 { 116 MBeanServer server = (MBeanServer ) i.next(); 117 if (server.getDefaultDomain().equals("jboss")) 118 { 119 return server; 120 } 121 } 122 throw new IllegalStateException ("No 'jboss' MBeanServer found!"); 123 } 124 } 125 | Popular Tags |