1 16 package org.mortbay.jetty.servlet.jmx; 17 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import javax.management.MBeanException ; 23 import javax.management.MBeanServer ; 24 import javax.management.ObjectName ; 25 26 import org.apache.commons.logging.Log; 27 import org.mortbay.log.LogFactory; 28 import org.mortbay.jetty.servlet.WebApplicationContext; 29 import org.mortbay.util.LifeCycleEvent; 30 import org.mortbay.util.LifeCycleListener; 31 import org.mortbay.util.LogSupport; 32 33 34 41 public class WebApplicationContextMBean extends ServletHttpContextMBean 42 { 43 private static final Log log = LogFactory.getLog(WebApplicationContextMBean.class); 44 private WebApplicationContext _webappContext; 45 private Map _configurations = new HashMap (); 46 47 48 51 public WebApplicationContextMBean() 52 throws MBeanException 53 {} 54 55 56 protected void defineManagedResource() 57 { 58 super.defineManagedResource(); 59 60 defineAttribute("displayName",false); 61 defineAttribute("defaultsDescriptor",true); 62 defineAttribute("WAR",true); 63 defineAttribute("extractWAR",true); 64 _webappContext=(WebApplicationContext)getManagedResource(); 65 _webappContext.addEventListener(new LifeCycleListener() 66 { 67 68 public void lifeCycleStarting (LifeCycleEvent event) 69 {} 70 71 public void lifeCycleStarted (LifeCycleEvent event) 72 { 73 getConfigurations(); 74 } 75 76 public void lifeCycleFailure (LifeCycleEvent event) 77 {} 78 79 public void lifeCycleStopping (LifeCycleEvent event) 80 {} 81 82 public void lifeCycleStopped (LifeCycleEvent event) 83 { 84 destroyConfigurations(); 85 } 86 87 }); 88 } 89 90 91 95 public void postRegister(Boolean ok) 96 { 97 super.postRegister(ok); 98 getConfigurations(); 99 } 100 101 102 103 104 105 109 public void postDeregister () 110 { 111 destroyConfigurations (); 112 super.postDeregister(); 113 } 114 115 116 121 public ObjectName [] getConfigurations () 122 { 123 return getComponentMBeans(_webappContext.getConfigurations(),_configurations); 124 } 125 126 public void destroyConfigurations () 127 { 128 MBeanServer mbeanServer = getMBeanServer(); 129 Iterator itor = _configurations.values().iterator(); 130 while (itor.hasNext()) 131 { 132 try 133 { 134 ObjectName o = (ObjectName )itor.next(); 135 log.debug("Unregistering: "+o); 136 137 if (null!=mbeanServer) 138 mbeanServer.unregisterMBean((ObjectName )o); 139 } 140 catch (Exception e) 141 { 142 log.warn(LogSupport.EXCEPTION, e); 143 } 144 } 145 _configurations.clear(); 146 } 147 148 149 150 151 } 152 | Popular Tags |