From 1bd123797a706b83ec2b3fce6c44d1b96832c0cc Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 14 Apr 2010 12:07:04 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49045 Add support for adding Services and Engines via JMX Based on a patch by Chamith Buddhika git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@933921 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/mbeans/MBeanFactory.java | 60 +++++++++++++-- .../apache/catalina/mbeans/mbeans-descriptors.xml | 85 ++-------------------- 2 files changed, 63 insertions(+), 82 deletions(-) diff --git a/java/org/apache/catalina/mbeans/MBeanFactory.java b/java/org/apache/catalina/mbeans/MBeanFactory.java index e63b7c5f9..66802bc1d 100644 --- a/java/org/apache/catalina/mbeans/MBeanFactory.java +++ b/java/org/apache/catalina/mbeans/MBeanFactory.java @@ -50,7 +50,6 @@ import org.apache.catalina.valves.AccessLogValve; import org.apache.catalina.valves.RemoteAddrValve; import org.apache.catalina.valves.RemoteHostValve; import org.apache.catalina.valves.ValveBase; -import org.apache.tomcat.util.modeler.BaseModelMBean; /** @@ -61,7 +60,7 @@ import org.apache.tomcat.util.modeler.BaseModelMBean; * @version $Revision$ $Date$ */ -public class MBeanFactory extends BaseModelMBean { +public class MBeanFactory { private static final org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory.getLog(MBeanFactory.class); @@ -548,9 +547,8 @@ public class MBeanFactory extends BaseModelMBean { String docBase) throws Exception { - // XXX for backward compatibility. Remove it once supported by the admin - return - createStandardContext(parent,path,docBase,false,false,false,false); + return createStandardContext(parent, path, docBase, false, false, + false, false); } /** @@ -687,6 +685,38 @@ public class MBeanFactory extends BaseModelMBean { /** + * Creates a new StandardService and StandardEngine. + * + * @param domain Domain name for the container instance + * @param defaultHost Name of the default host to be used in the Engine + * @param baseDir Base directory value for Engine + * + * @exception Exception if an MBean cannot be created or registered + */ + public String createStandardServiceEngine(String domain, + String defaultHost, String baseDir) throws Exception{ + + if (!(container instanceof Server)) { + throw new Exception(); + } + + StandardEngine engine = new StandardEngine(); + engine.setDomain(domain); + engine.setName(domain); + engine.setDefaultHost(defaultHost); + engine.setBaseDir(baseDir); + + Service service = new StandardService(); + service.setContainer(engine); + service.setName(domain); + + ((Server) container).addService(service); + + return engine.getJmxName().toString(); + } + + + /** * Create a new StandardManager. * * @param parent MBean Name of the associated parent component @@ -946,6 +976,26 @@ public class MBeanFactory extends BaseModelMBean { /** + * Remove an existing Service. + * + * @param name MBean Name of the component to remove + * + * @exception Exception if a component cannot be removed + */ + public void removeService(String name) throws Exception { + + if (!(container instanceof Server)) { + throw new Exception(); + } + + // Acquire a reference to the component to be removed + ObjectName oname = new ObjectName(name); + Service service = getService(oname); + ((Server) container).removeService(service); + } + + + /** * Remove an existing Valve. * * @param name MBean Name of the component to remove diff --git a/java/org/apache/catalina/mbeans/mbeans-descriptors.xml b/java/org/apache/catalina/mbeans/mbeans-descriptors.xml index 4f0961574..6b23013c4 100644 --- a/java/org/apache/catalina/mbeans/mbeans-descriptors.xml +++ b/java/org/apache/catalina/mbeans/mbeans-descriptors.xml @@ -18,7 +18,7 @@ @@ -81,15 +81,6 @@ type="java.lang.String"/> - - - - - - - - - - - - - - @@ -276,39 +249,6 @@ type="java.lang.String"/> - - - - - - - - - - - - - - - - - -