amyroh 01/11/13 19:51:06 Modified: catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java StandardEngineMBean.java StandardServerMBean.java StandardServiceMBean.java mbeans-descriptors.xml Log: Add additional operations for MBeans. Revision Changes Path 1.6 +259 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java Index: MBeanUtils.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MBeanUtils.java 2001/11/11 19:55:08 1.5 +++ MBeanUtils.java 2001/11/14 03:51:06 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v 1.5 2001/11/11 19:55:08 remm Exp $ - * $Revision: 1.5 $ - * $Date: 2001/11/11 19:55:08 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v 1.6 2001/11/14 03:51:06 amyroh Exp $ + * $Revision: 1.6 $ + * $Date: 2001/11/14 03:51:06 $ * * ==================================================================== * @@ -78,16 +78,21 @@ import javax.management.modelmbean.ModelMBean; import com.sun.management.jmx.Trace; import org.apache.catalina.Connector; +import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; +import org.apache.catalina.Logger; +import org.apache.catalina.Realm; import org.apache.catalina.Server; import org.apache.catalina.ServerFactory; import org.apache.catalina.Service; +import org.apache.catalina.Valve; import org.apache.catalina.connector.http.HttpConnector; import org.apache.catalina.connector.warp.WarpConnector; +import org.apache.catalina.valves.ValveBase; import org.apache.commons.modeler.ManagedBean; import org.apache.commons.modeler.Registry; @@ -97,7 +102,7 @@ * * @author Craig R. McClanahan * @author Amy Roh - * @version $Revision: 1.5 $ $Date: 2001/11/11 19:55:08 $ + * @version $Revision: 1.6 $ $Date: 2001/11/14 03:51:06 $ */ public class MBeanUtils { @@ -256,6 +261,52 @@ /** * Create, register, and return an MBean for this + * <code>Logger</code> object. + * + * @param logger The Logger to be managed + * + * @exception Exception if an MBean cannot be created or registered + */ + public static ModelMBean createMBean(Logger logger) + throws Exception { + + String mname = createManagedName(logger); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ModelMBean mbean = managed.createMBean(logger); + ObjectName oname = createObjectName(domain, logger); + mserver.registerMBean(mbean, oname); + return (mbean); + + } + + + /** + * Create, register, and return an MBean for this + * <code>Realm</code> object. + * + * @param realm The Realm to be managed + * + * @exception Exception if an MBean cannot be created or registered + */ + public static ModelMBean createMBean(Realm realm) + throws Exception { + + String mname = createManagedName(realm); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ModelMBean mbean = managed.createMBean(realm); + ObjectName oname = createObjectName(domain, realm); + mserver.registerMBean(mbean, oname); + return (mbean); + + } + /** + * Create, register, and return an MBean for this * <code>Server</code> object. * * @param server The Server to be managed @@ -303,6 +354,29 @@ /** + * Create, register, and return an MBean for this + * <code>Valve</code> object. + * + * @param valve The Valve to be managed + * + * @exception Exception if an MBean cannot be created or registered + */ + public static ModelMBean createMBean(Valve valve) + throws Exception { + + String mname = createManagedName(valve); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ModelMBean mbean = managed.createMBean(valve); + ObjectName oname = createObjectName(domain, valve); + mserver.registerMBean(mbean, oname); + return (mbean); + + } + + /** * Create an <code>ObjectName</code> for this * <code>Connector</code> object. * @@ -424,6 +498,84 @@ /** * Create an <code>ObjectName</code> for this + * <code>Logger</code> object. + * + * @param domain Domain in which this name is to be created + * @param logger The Logger to be named + * + * @exception MalformedObjectNameException if a name cannot be created + */ + public static ObjectName createObjectName(String domain, + Logger logger) + throws MalformedObjectNameException { + + ObjectName name = null; + Container container = logger.getContainer(); + + if (container instanceof Engine) { + Service service = ((Engine)container).getService(); + name = new ObjectName(domain + ":type=Logger,service=" + + service.getName()); + } else if (container instanceof Host) { + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Logger,host=" + + container.getName() + ",service=" + + service.getName()); + } else if (container instanceof Context) { + String path = ((Context)container).getPath(); + Host host = (Host) container.getParent(); + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Logger,path=" + path + + ",host=" + host.getName() + ",service=" + + service.getName()); + } + + return (name); + + } + + + /** + * Create an <code>ObjectName</code> for this + * <code>Realm</code> object. + * + * @param domain Domain in which this name is to be created + * @param realm The Realm to be named + * + * @exception MalformedObjectNameException if a name cannot be created + */ + public static ObjectName createObjectName(String domain, + Realm realm) + throws MalformedObjectNameException { + + ObjectName name = null; + Container container = realm.getContainer(); + + if (container instanceof Engine) { + Service service = ((Engine)container).getService(); + name = new ObjectName(domain + ":type=Realm,service=" + + service.getName()); + } else if (container instanceof Host) { + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Realm,host=" + + container.getName() + ",service=" + + service.getName()); + } else if (container instanceof Context) { + String path = ((Context)container).getPath(); + Host host = (Host) container.getParent(); + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Realm,path=" + path + + ",host=" + host.getName() + ",service=" + + service.getName()); + } + + return (name); + + } + + + /** + * Create an <code>ObjectName</code> for this * <code>Server</code> object. * * @param domain Domain in which this name is to be created @@ -464,6 +616,44 @@ /** + * Create an <code>ObjectName</code> for this + * <code>Valve</code> object. + * + * @param domain Domain in which this name is to be created + * @param valve The Valve to be named + * + * @exception MalformedObjectNameException if a name cannot be created + */ + public static ObjectName createObjectName(String domain, + Valve valve) + throws MalformedObjectNameException { + + ObjectName name = null; + Container container = ((ValveBase)valve).getContainer(); + + if (container instanceof Engine) { + Service service = ((Engine)container).getService(); + name = new ObjectName(domain + ":type=Valve,service=" + + service.getName()); //FIX ME - add sequence # + } else if (container instanceof Host) { + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Valve,host=" + + container.getName() + ",service=" + + service.getName()); //FIX ME - add sequence # + } else if (container instanceof Context) { + String path = ((Context)container).getPath(); + Host host = (Host) container.getParent(); + Service service = ((Engine)container.getParent()).getService(); + name = new ObjectName(domain + ":type=Valve,path=" + path + + ",host=" + host.getName() + ",service=" + + service.getName()); //FIX ME - add sequence # + } + + return (name); + + } + + /** * Create and configure (if necessary) and return the registry of * managed object descriptions. */ @@ -600,6 +790,50 @@ /** * Deregister the MBean for this + * <code>Logger</code> object. + * + * @param logger The Logger to be managed + * + * @exception Exception if an MBean cannot be deregistered + */ + public static void destroyMBean(Logger logger) + throws Exception { + + String mname = createManagedName(logger); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ObjectName oname = createObjectName(domain, logger); + mserver.unregisterMBean(oname); + + } + + + /** + * Deregister the MBean for this + * <code>Realm</code> object. + * + * @param realm The Realm to be managed + * + * @exception Exception if an MBean cannot be deregistered + */ + public static void destroyMBean(Realm realm) + throws Exception { + + String mname = createManagedName(realm); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ObjectName oname = createObjectName(domain, realm); + mserver.unregisterMBean(oname); + + } + + + /** + * Deregister the MBean for this * <code>Server</code> object. * * @param server The Server to be managed @@ -641,5 +875,26 @@ } + + /** + * Deregister the MBean for this + * <code>Valve</code> object. + * + * @param valve The Valve to be managed + * + * @exception Exception if an MBean cannot be deregistered + */ + public static void destroyMBean(Valve valve) + throws Exception { + + String mname = createManagedName(valve); + ManagedBean managed = registry.findManagedBean(mname); + String domain = managed.getDomain(); + if (domain == null) + domain = mserver.getDefaultDomain(); + ObjectName oname = createObjectName(domain, valve); + mserver.unregisterMBean(oname); + + } } 1.3 +100 -29 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardEngineMBean.java Index: StandardEngineMBean.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardEngineMBean.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardEngineMBean.java 2001/11/09 02:19:07 1.2 +++ StandardEngineMBean.java 2001/11/14 03:51:06 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardEngineMBean.java,v 1.2 2001/11/09 02:19:07 amyroh Exp $ - * $Revision: 1.2 $ - * $Date: 2001/11/09 02:19:07 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardEngineMBean.java,v 1.3 2001/11/14 03:51:06 amyroh Exp $ + * $Revision: 1.3 $ + * $Date: 2001/11/14 03:51:06 $ * * ==================================================================== * @@ -66,15 +66,26 @@ import javax.management.MBeanException; import javax.management.RuntimeOperationsException; +import org.apache.catalina.Container; import org.apache.catalina.Engine; import org.apache.catalina.Host; +import org.apache.catalina.Logger; import org.apache.catalina.Service; +import org.apache.catalina.Realm; import org.apache.catalina.Valve; import org.apache.catalina.core.StandardHost; +import org.apache.catalina.core.StandardEngine; +import org.apache.catalina.logger.FileLogger; +import org.apache.catalina.logger.SystemErrLogger; +import org.apache.catalina.logger.SystemOutLogger; +import org.apache.catalina.realm.JDBCRealm; +import org.apache.catalina.realm.JNDIRealm; +import org.apache.catalina.realm.MemoryRealm; import org.apache.catalina.valves.AccessLogValve; import org.apache.catalina.valves.RemoteAddrValve; import org.apache.catalina.valves.RemoteHostValve; import org.apache.catalina.valves.RequestDumperValve; +import org.apache.catalina.valves.ValveBase; import org.apache.commons.modeler.BaseModelMBean; @@ -83,7 +94,7 @@ * <code>org.apache.catalina.core.StandardEngine</code> component.</p> * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2001/11/09 02:19:07 $ + * @version $Revision: 1.3 $ $Date: 2001/11/14 03:51:06 $ */ public class StandardEngineMBean extends BaseModelMBean { @@ -129,63 +140,123 @@ /** - * Create a new AccessLogger. + * Create a new <code>AccessLogger<code>. + * + * @exception Exception if an MBean cannot be created or registered */ - public AccessLogValve createAccessLogger(int debug, String directory, - String pattern, String prefix, boolean resolveHosts, String suffix) { + public void createAccessLogger() + throws Exception { AccessLogValve accessLogger = new AccessLogValve(); - - //accessLogger.setDebug(debug); FIX ME - no debug property existS - accessLogger.setDirectory(directory); - accessLogger.setPattern(pattern); - accessLogger.setPrefix(prefix); - accessLogger.setResolveHosts(resolveHosts); - accessLogger.setSuffix(suffix); - return accessLogger; + StandardEngine engine = (StandardEngine) this.resource; + accessLogger.setContainer(engine); + engine.addValve(accessLogger); + MBeanUtils.createMBean(accessLogger); } /** - * Create a new Host. + * Create a new <code>Host<code>. + * + * @param name The new Host's name + * + * @exception Exception if an MBean cannot be created or registered */ - public Host createHost(String appBase, int debug, String name, - boolean unpackWARs) { + public void createHost(String name) + throws Exception { StandardHost host = new StandardHost(); - host.setAppBase(appBase); - host.setDebug(debug); host.setName(name); - host.setUnpackWARs(unpackWARs); + Engine engine = (Engine) this.resource; + engine.addChild(host); + MBeanUtils.createMBean(host); + + } + + + /** + * Create a new <code>Logger<code>. + * + * @param type the type of Logger to be created -- FIX ME + * + * @exception Exception if an MBean cannot be created or registered + */ + public void createLogger(String type) + throws Exception { + + Logger logger = null; + + if (type.equals("FileLogger")) { + logger = new FileLogger(); + } else if (type.equals("SystemErrLogger")) { + logger = new SystemErrLogger(); + } else if (type.equals("SystemOutLogger")) { + logger = new SystemOutLogger(); + } - return host; + StandardEngine engine = (StandardEngine) this.resource; + logger.setContainer((Container) engine); + engine.setLogger(logger); + MBeanUtils.createMBean(logger); } /** + * Create a new <code>Realm<code>. + * + * @param type the type of Realm to be created -- FIX ME + * + * @exception Exception if an MBean cannot be created or registered + */ + public void createRealm(String type) + throws Exception { + + Realm realm = null; + + if (type.equals("JDBCRealm")) { + realm = new JDBCRealm(); + } else if (type.equals("JNDIRealm")) { + realm = new JNDIRealm(); + } else if (type.equals("MemoryRealm")) { + realm = new MemoryRealm(); + } + + StandardEngine engine = (StandardEngine) this.resource; + realm.setContainer((Container) engine); + engine.setRealm(realm); + MBeanUtils.createMBean(realm); + + } + + + /** * Create a new RequestFilterValve. + * + * @param type the type of valve to be created -- FIX ME need to pass type + * + * @exception Exception if an MBean cannot be created or registered */ - public Valve createRequestFilterValve(String type, String allow, - int debug, String deny) { + public void createRequestFilterValve(String type) //type needed? + throws Exception { Valve valve = null; + if (type.equals("RemoteAddrValve")) { valve = new RemoteAddrValve(); - ((RemoteAddrValve)valve).setAllow(allow); - ((RemoteAddrValve)valve).setDeny(deny); } else if (type.equals("RemostHostValve")) { valve = new RemoteHostValve(); - ((RemoteHostValve)valve).setAllow(allow); - ((RemoteHostValve)valve).setDeny(deny); } else if (type.equals("RequestDumperValve")) { valve = new RequestDumperValve(); } - return valve; + StandardEngine engine = (StandardEngine) this.resource; + ((ValveBase)valve).setContainer((Container) engine); + engine.addValve(valve); + MBeanUtils.createMBean(valve); } 1.3 +6 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java Index: StandardServerMBean.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardServerMBean.java 2001/11/13 02:36:49 1.2 +++ StandardServerMBean.java 2001/11/14 03:51:06 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.2 2001/11/13 02:36:49 amyroh Exp $ - * $Revision: 1.2 $ - * $Date: 2001/11/13 02:36:49 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.3 2001/11/14 03:51:06 amyroh Exp $ + * $Revision: 1.3 $ + * $Date: 2001/11/14 03:51:06 $ * * ==================================================================== * @@ -79,7 +79,7 @@ * <code>org.apache.catalina.core.StandardServer</code> component.</p> * * @author Amy Roh - * @version $Revision: 1.2 $ $Date: 2001/11/13 02:36:49 $ + * @version $Revision: 1.3 $ $Date: 2001/11/14 03:51:06 $ */ public class StandardServerMBean extends BaseModelMBean { @@ -113,7 +113,7 @@ // ------------------------------------------------------------- Operations /** - * Create a new child Service and Engine. + * Create a new child <code>Service</code> and <code>Engine</code>. * * @param name The new Service's name * @@ -130,7 +130,7 @@ MBeanUtils.createMBean(service); StandardEngine engine = new StandardEngine(); - service.setContainer((Container)engine); + service.setContainer(engine); MBeanUtils.createMBean(engine); } 1.4 +5 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServiceMBean.java Index: StandardServiceMBean.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServiceMBean.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StandardServiceMBean.java 2001/11/13 02:36:49 1.3 +++ StandardServiceMBean.java 2001/11/14 03:51:06 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServiceMBean.java,v 1.3 2001/11/13 02:36:49 amyroh Exp $ - * $Revision: 1.3 $ - * $Date: 2001/11/13 02:36:49 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServiceMBean.java,v 1.4 2001/11/14 03:51:06 amyroh Exp $ + * $Revision: 1.4 $ + * $Date: 2001/11/14 03:51:06 $ * * ==================================================================== * @@ -78,7 +78,7 @@ * <code>org.apache.catalina.core.StandardService</code> component.</p> * * @author Amy Roh - * @version $Revision: 1.3 $ $Date: 2001/11/13 02:36:49 $ + * @version $Revision: 1.4 $ $Date: 2001/11/14 03:51:06 $ */ public class StandardServiceMBean extends BaseModelMBean { @@ -124,7 +124,7 @@ /** - * Create a new Connector. + * Create a new <code>Connector</code>. * * @param address The IP address on which to bind * @param port TCP port number to listen on 1.11 +43 -1 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml Index: mbeans-descriptors.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/mbeans-descriptors.xml,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- mbeans-descriptors.xml 2001/11/13 02:36:49 1.10 +++ mbeans-descriptors.xml 2001/11/14 03:51:06 1.11 @@ -6,7 +6,7 @@ <!-- Descriptions of JMX MBeans for Catalina - $Id: mbeans-descriptors.xml,v 1.10 2001/11/13 02:36:49 amyroh Exp $ + $Id: mbeans-descriptors.xml,v 1.11 2001/11/14 03:51:06 amyroh Exp $ --> <mbeans-descriptors> @@ -689,6 +689,48 @@ <constructor name="StandardEngine"/> + <operation name="createAccessLogger" + description="Create a new AccessLogger" + impact="ACTION" + returnType="void"/> + </operation> + + <operation name="createHost" + description="Create a new Host" + impact="ACTION" + returnType="void"> + <parameter name="name" + description="The new Host's name" + type="java.lang.String"/> + </operation> + + <operation name="createLogger" + description="Create a new Logger" + impact="ACTION" + returnType="void"> + <parameter name="type" + description="the type of Logger to be created" + type="java.lang.String"/> + </operation> + + <operation name="createRealm" + description="Create a new Realm" + impact="ACTION" + returnType="void"> + <parameter name="type" + description="the type of Realm to be created" + type="java.lang.String"/> + </operation> + + <operation name="createRequestFilterValve" + description="Create a new RequestFilterValve" + impact="ACTION" + returnType="void"> + <parameter name="type" + description="the type of RequestFilterValve to be created" + type="java.lang.String"/> + </operation> + <operation name="addChild" description="Add a new child Container to those associated with this Container" impact="ACTION"
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>