1 16 package org.mortbay.jetty.jmx; 17 18 import java.io.IOException ; 19 20 import javax.management.InstanceNotFoundException ; 21 import javax.management.MBeanException ; 22 import javax.management.MBeanServer ; 23 import javax.management.ObjectName ; 24 25 import org.apache.commons.logging.Log; 26 import org.mortbay.log.LogFactory; 27 import org.mortbay.http.jmx.HttpServerMBean; 28 import org.mortbay.jetty.Server; 29 import org.mortbay.util.LogSupport; 30 31 32 41 public class ServerMBean extends HttpServerMBean 42 { 43 private static Log log = LogFactory.getLog(ServerMBean.class); 44 45 private Server _jettyServer; 46 private String _configuration; 47 48 49 53 public ServerMBean(Server jettyServer) 54 throws MBeanException , InstanceNotFoundException 55 { 56 super(jettyServer); 57 } 58 59 60 64 public ServerMBean() 65 throws MBeanException , InstanceNotFoundException 66 { 67 this(new Server ()); 68 } 69 70 71 77 public ServerMBean(String configuration) 78 throws IOException ,MBeanException , InstanceNotFoundException 79 { 80 this(new Server ()); 81 _configuration=configuration; 82 } 83 84 85 protected ObjectName newObjectName(MBeanServer server) 86 { 87 return uniqueObjectName(server, getDefaultDomain()+":Server="); 88 } 89 90 91 protected void defineManagedResource() 92 { 93 super.defineManagedResource(); 94 95 defineAttribute("configuration"); 96 defineAttribute("rootWebApp"); 97 defineAttribute("webApplicationConfigurationClassNames"); 98 defineOperation("addWebApplication", 99 new String []{"java.lang.String", 100 "java.lang.String"}, 101 IMPACT_ACTION); 102 103 defineOperation("addWebApplication", 104 new String []{"java.lang.String", 105 "java.lang.String", 106 "java.lang.String"}, 107 IMPACT_ACTION); 108 defineOperation("addWebApplications", 109 new String []{"java.lang.String", 110 "java.lang.String"}, 111 IMPACT_ACTION); 112 _jettyServer=(Server )getManagedResource(); 113 } 114 115 116 117 118 121 public void postRegister(Boolean ok) 122 { 123 super.postRegister(ok); 124 125 if (ok.booleanValue()) 126 { 127 if (_configuration!=null) 128 { 129 try 130 { 131 _jettyServer.configure(_configuration); 132 _jettyServer.start(); 133 } 134 catch(Exception e) 135 { 136 log.warn(LogSupport.EXCEPTION,e); 137 } 138 } 139 } 140 } 141 142 143 public void postDeregister() 144 { 145 _configuration=null; 146 try 147 { 148 if (null!=_jettyServer) 149 _jettyServer.stop(); 150 } 151 catch(Exception e) 152 { 153 log.warn(e); 154 } 155 finally 156 { 157 super.postDeregister(); 158 } 159 160 } 161 } 162 | Popular Tags |