1 29 30 package com.caucho.jmx; 31 32 import com.caucho.loader.DynamicClassLoader; 33 import com.caucho.loader.EnvironmentLocal; 34 import com.caucho.log.Log; 35 import com.caucho.util.L10N; 36 37 import javax.management.MBeanServerDelegate ; 38 import javax.management.MBeanServerDelegateMBean ; 39 import java.util.logging.Level ; 40 import java.util.logging.Logger ; 41 42 45 public class EnvironmentMBeanServer extends AbstractMBeanServer { 46 private static final L10N L = new L10N(EnvironmentMBeanServer.class); 47 private static final Logger log = Log.open(EnvironmentMBeanServer.class); 48 49 private EnvironmentLocal<MBeanContext> _localContext = 50 new EnvironmentLocal<MBeanContext>(); 51 52 private MBeanServerDelegate _globalDelegate; 53 54 57 public EnvironmentMBeanServer(String domain, MBeanServerDelegate delegate) 58 { 59 super(domain); 60 61 if (Jmx.getMBeanServer() == null) 62 Jmx.setMBeanServer(this); 63 64 ClassLoader systemLoader = ClassLoader.getSystemClassLoader(); 65 66 MBeanContext context = new MBeanContext(this, systemLoader, delegate); 67 68 _localContext.set(context, systemLoader); 69 70 try { 71 IntrospectionMBean mbean; 72 mbean = new IntrospectionMBean(delegate, MBeanServerDelegateMBean .class); 73 74 MBeanWrapper mbeanWrapper; 75 mbeanWrapper = new MBeanWrapper(context, SERVER_DELEGATE_NAME, 76 delegate, mbean); 77 78 context.registerMBean(mbeanWrapper, SERVER_DELEGATE_NAME); 79 } catch (Exception e) { 80 log.log(Level.WARNING, e.toString(), e); 81 } 82 } 83 84 87 protected MBeanContext getContext(ClassLoader loader) 88 { 89 synchronized (_localContext) { 90 MBeanContext context = _localContext.getLevel(loader); 91 92 if (context == null) { 93 if (loader instanceof DynamicClassLoader 94 && ((DynamicClassLoader) loader).isDestroyed()) 95 throw new IllegalStateException (L.l("JMX context {0} has been closed.", 96 loader)); 97 98 MBeanServerDelegate delegate; 99 delegate = new MBeanServerDelegateImpl("Resin-JMX"); 100 101 context = new MBeanContext(this, loader, delegate); 102 103 MBeanContext parent = null; 104 105 if (loader != null) 106 parent = getContext(loader.getParent()); 107 108 if (parent != null) 109 context.setProperties(parent.copyProperties()); 110 111 _localContext.set(context, loader); 112 113 try { 114 IntrospectionMBean mbean; 115 mbean = new IntrospectionMBean(delegate, MBeanServerDelegateMBean .class); 116 117 MBeanWrapper mbeanWrapper; 118 mbeanWrapper = new MBeanWrapper(context, SERVER_DELEGATE_NAME, 119 delegate, mbean); 120 121 context.registerMBean(mbeanWrapper, SERVER_DELEGATE_NAME); 122 } catch (Exception e) { 123 log.log(Level.WARNING, e.toString(), e); 124 } 125 } 126 127 return context; 128 } 129 } 130 131 134 protected MBeanContext getExistingContext(ClassLoader loader) 135 { 136 if (loader == null) 137 return _localContext.get(ClassLoader.getSystemClassLoader()); 138 139 synchronized (_localContext) { 140 return _localContext.getLevel(loader); 141 } 142 } 143 144 147 protected void removeContext(MBeanContext context, ClassLoader loader) 148 { 149 if (_localContext.get(loader) == context) 150 _localContext.remove(loader); 151 } 152 153 156 public String toString() 157 { 158 return "EnvironmentMBeanServer[]"; 159 } 160 } 161 | Popular Tags |