1 28 29 package com.caucho.jmx; 30 31 import com.caucho.log.Log; 32 33 import javax.management.MBeanServer ; 34 import javax.management.MBeanServerDelegate ; 35 import java.lang.reflect.Method ; 36 import java.util.logging.Level ; 37 import java.util.logging.Logger ; 38 39 42 public class EnvironmentMBeanServerBuilder { private static final Logger log = Log.open(EnvironmentMBeanServerBuilder.class); 44 45 private static MBeanServer _globalServer; 46 47 private MBeanServer _mbeanServer; 48 private boolean _isInit; 49 50 public EnvironmentMBeanServerBuilder() 51 { 52 } 53 54 57 public MBeanServerDelegate newMBeanServerDelegate() 58 { 59 return new MBeanServerDelegateImpl("Resin-JMX"); 60 } 61 62 65 public MBeanServer newMBeanServer(String defaultDomain, 66 MBeanServer outer, 67 MBeanServerDelegate delegate) 68 { 69 if (! _isInit) { 70 _isInit = true; 71 72 try { 73 Class cl = Class.forName("java.lang.management.ManagementFactory"); 74 75 Method method = cl.getMethod("getPlatformMBeanServer", new Class [0]); 76 77 _mbeanServer = (MBeanServer ) method.invoke(null, new Object [0]); 78 79 return _mbeanServer; 80 } catch (ClassNotFoundException e) { 81 } catch (Throwable e) { 82 log.log(Level.WARNING, e.toString(), e); 83 } 84 } 85 86 if (_mbeanServer == null) { 87 if (defaultDomain == null) 88 defaultDomain = "resin"; 89 90 } 92 93 return _mbeanServer; 94 } 95 96 99 public static MBeanServer getGlobal(String defaultDomain) 100 { 101 if (_globalServer == null) { 102 if (defaultDomain == null) 103 defaultDomain = "resin"; 104 105 MBeanServerDelegateImpl delegate; 106 delegate = new MBeanServerDelegateImpl("Resin-JMX"); 107 _globalServer = new EnvironmentMBeanServer(defaultDomain, delegate); 108 } 109 110 return _globalServer; 111 } 112 } 113 | Popular Tags |