Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49045
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 14 Apr 2010 12:07:04 +0000 (12:07 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 14 Apr 2010 12:07:04 +0000 (12:07 +0000)
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
java/org/apache/catalina/mbeans/mbeans-descriptors.xml

index e63b7c5..66802bc 100644 (file)
@@ -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
index 4f09615..6b23013 100644 (file)
@@ -18,7 +18,7 @@
 <mbeans-descriptors>
 
   <mbean         name="MBeanFactory"
-            className="org.apache.catalina.mbeans.MBeanFactory"
+                 type="org.apache.catalina.mbeans.MBeanFactory"
           description="Factory for MBeans and corresponding components"
                domain="Catalina">
 
                  type="java.lang.String"/>
     </operation>
 
-    <operation   name="createFileLogger"
-          description="Create a new FileLogger"
-               impact="ACTION"
-           returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent component"
-                 type="java.lang.String"/>
-    </operation>
-
     <operation   name="createHttpConnector"
           description="Create a new HttpConnector"
                impact="ACTION"
                  type="java.lang.String"/>
     </operation>
 
-    <operation   name="createStandardEngine"
-          description="Create a new StandardEngine"
+    <operation   name="createStandardServiceEngine"
+          description="Create a new StandardService and StandardEngine"
                impact="ACTION"
            returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent component"
-                 type="java.lang.String"/>
-      <parameter name="name"
-          description="Unique name of this Engine"
-                 type="java.lang.String"/>
-      <parameter name="defaultHost"
-          description="Default host name for this Engine"
-                 type="java.lang.String"/>
-    </operation>
-
-    <operation   name="createStandardEngineService"
-          description="Create a new StandardEngine and StandardService"
-               impact="ACTION"
-           returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent Service"
-                 type="java.lang.String"/>
-      <parameter name="engineName"
-          description="Unique name of this Engine"
+      <parameter name="domain"
+          description="Domain used for MBeans associated with the new Service"
                  type="java.lang.String"/>
       <parameter name="defaultHost"
-          description="Default host name for this Engine"
+          description="Default host name for the new Engine"
                  type="java.lang.String"/>
-      <parameter name="serviceName"
-          description="Unique name of this Service"
+      <parameter name="baseDir"
+          description="Base directory value for the new Engine"
                  type="java.lang.String"/>
     </operation>
 
                  type="java.lang.String"/>
     </operation>
 
-    <operation   name="createStandardService"
-          description="Create a new StandardService"
-               impact="ACTION"
-           returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent component"
-                 type="java.lang.String"/>
-      <parameter name="name"
-          description="Unique name of this Service"
-                 type="java.lang.String"/>
-      <parameter name="domain"
-          description="The domain of this Service"
-                 type="java.lang.String"/>
-    </operation>
-
-    <operation   name="createSystemErrLogger"
-          description="Create a new System Error Logger"
-               impact="ACTION"
-           returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent component"
-                 type="java.lang.String"/>
-    </operation>
-
-    <operation   name="createSystemOutLogger"
-          description="Create a new System Output Logger"
-               impact="ACTION"
-           returnType="java.lang.String">
-      <parameter name="parent"
-          description="MBean Name of the associated parent component"
-                 type="java.lang.String"/>
-    </operation>
-
     <operation   name="createUserDatabaseRealm"
           description="Create a new UserDatabase Realm"
                impact="ACTION"
                  type="java.lang.String"/>
     </operation>
 
-    <operation   name="removeLogger"
-          description="Remove an existing Logger"
-               impact="ACTION"
-           returnType="void">
-      <parameter name="name"
-          description="MBean Name of the component to be removed"
-                 type="java.lang.String"/>
-    </operation>
-
     <operation   name="removeManager"
           description="Remove an existing Manager"
                impact="ACTION"