1 25 package org.objectweb.jonas.web.jetty50.jmx; 26 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.management.MBeanException ; 32 import javax.management.ObjectName ; 33 34 import org.mortbay.jetty.servlet.ServletHolder; 35 import org.mortbay.jetty.servlet.WebApplicationContext; 36 import org.mortbay.jetty.servlet.jmx.ConfigurationMBean; 37 import org.mortbay.util.LogSupport; 38 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 import org.objectweb.jonas.web.jetty50.JSR77Configuration; 43 44 53 public class JSR77ConfigurationMBean extends ConfigurationMBean { 54 55 58 private static Log log = LogFactory.getLog(JSR77ConfigurationMBean.class); 59 60 63 private Map jsr77MBeanMap = new HashMap (); 64 65 69 public JSR77ConfigurationMBean() throws MBeanException { 70 super(); 71 } 72 73 76 protected void defineManagedResource() { 77 super.defineManagedResource(); 78 } 79 80 86 87 public void postRegister(Boolean ok) { 88 super.postRegister(ok); 89 try { 90 defineJsr77MBeans(); 91 } catch (Exception e) { 92 log.warn(LogSupport.EXCEPTION, e); 93 } 94 } 95 96 102 public void postDeregister() { 103 Iterator itor = jsr77MBeanMap.entrySet().iterator(); 104 while (itor.hasNext()) { 105 try { 106 Map.Entry entry = (Map.Entry ) itor.next(); 107 getMBeanServer().unregisterMBean((ObjectName ) entry.getValue()); 108 } catch (Exception e) { 109 log.warn(LogSupport.EXCEPTION, e); 110 } 111 } 112 } 113 114 121 private void defineJsr77MBeans() throws Exception { 122 WebApplicationContext context = ((JSR77Configuration) _config).getWebApplicationContext(); 123 124 J2EEWebModuleMBean wm = new J2EEWebModuleMBean(); 126 wm.setManagedResource(context, "objectReference"); 127 wm.setBaseObjectName(getBaseObjectName().toString()); 128 ObjectName oName = getMBeanServer().registerMBean(wm, null).getObjectName(); 129 jsr77MBeanMap.put(context.getName(), oName); 130 131 133 ServletHolder[] servlets = context.getServletHandler().getServlets(); 134 for (int i = 0; null != servlets && i < servlets.length; i++) { 135 FixedJsr77ServletHolderMBean mbean = new FixedJsr77ServletHolderMBean(); 136 mbean.setManagedResource(servlets[i], "objectReference"); 137 mbean.setBaseObjectName(getBaseObjectName().toString()); 138 mbean.setJ2EEDomainName((String ) context.getAttribute("J2EEDomainName")); 140 mbean.setJ2EEApplicationName((String ) context.getAttribute("J2EEApplicationName")); 141 mbean.setJ2EEServerName((String ) context.getAttribute("J2EEServerName")); 142 oName = getMBeanServer().registerMBean(mbean, null).getObjectName(); 143 jsr77MBeanMap.put(servlets[i].getName(), oName); 144 } 145 } 146 147 } 148 | Popular Tags |