cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml
craigmcc02/04/26 10:40:50 Modified:catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml Log: Enable saving of most of the simple-to-access configuration elements. There are FIXMEs to mark the remaining ones. Revision ChangesPath 1.9 +407 -14 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- StandardServerMBean.java 26 Apr 2002 02:27:33 - 1.8 +++ StandardServerMBean.java 26 Apr 2002 17:40:50 - 1.9 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.8 2002/04/26 02:27:33 craigmcc Exp $ - * $Revision: 1.8 $ - * $Date: 2002/04/26 02:27:33 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.9 2002/04/26 17:40:50 craigmcc Exp $ + * $Revision: 1.9 $ + * $Date: 2002/04/26 17:40:50 $ * * * @@ -68,6 +68,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Iterator; import javax.management.InstanceNotFoundException; import javax.management.MBeanAttributeInfo; import javax.management.MBeanException; @@ -85,7 +86,7 @@ * codeorg.apache.catalina.core.StandardServer/code component./p * * @author Amy Roh - * @version $Revision: 1.8 $ $Date: 2002/04/26 02:27:33 $ + * @version $Revision: 1.9 $ $Date: 2002/04/26 17:40:50 $ */ public class StandardServerMBean extends BaseModelMBean { @@ -258,14 +259,17 @@ if (managedResource.equals(aname)) { continue; // KLUDGE - these should be removed } -if (!ainfo[i].isReadable() || !ainfo[i].isWritable()) { -continue; // We cannot configure this attribute +if (!ainfo[i].isReadable()) { +continue; // We cannot read the current value +} +if (!className.equals(aname) !ainfo[i].isWritable()) { +continue; // We will not be able to configure this attribute } // Acquire the value of this attribute Object value = mserver.getAttribute(oname, aname); if (value == null) { -value = ; +continue; // No need to explicitly record this } if (!(value instanceof String)) { value = value.toString(); @@ -285,6 +289,358 @@ /** + * Store the specified Connector properties. + * + * @param writer PrintWriter to which we are storing + * @param indent Number of spaces to indent this element + * @param oname ObjectName of the MBean for the object we are storing + * + * @exception Exception if an exception occurs while storing + */ +private void storeConnector(PrintWriter writer, int indent, +ObjectName oname) throws Exception { + +// Store the beginning of this element +for (int i = 0; i indent; i++) { +writer.print(' '); +} +writer.print(Connector); +storeAttributes(writer, oname); +writer.println(); + +// Store nested Listener elements +; // FIXME + +// Store nested Factory element +; // FIXME + +// Store the ending of this element +for (int i = 0; i indent; i++) { +writer.print(' '); +} +writer.println(/Connector); + +} + + +/** + * Store the specified Context properties. + * + * @param writer PrintWriter to which we are storing + * @param indent Number of spaces to indent this element + * @param oname ObjectName of the MBean for the object we are storing + * + * @exception Exception if an exception occurs while storing + */ +private void storeContext(PrintWriter writer, int indent, + ObjectName oname) throws Exception { + +// Store the beginning of this element +for (int i = 0; i indent; i++) { +writer.print(' '); +} +writer.print(Context); +storeAttributes(writer, oname); +writer.println(); + +// Store nested InstanceListener elements +; // FIXME + +// Store nested Listener elements +; // FIXME +
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml
craigmcc02/04/26 22:09:03 Modified:catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml Log: Switch to using the Catalina component tree directly for all persistence operations -- since we will need this for components that are not reflected as MBeans directly anyway, it's better to be consistent. This still leaves a few FIXMEs, but for the most part a running Catalina configuration is faithfully recorded into a conf/server.xml.new file that would (if renamed) reproduce the same configuration after a restart. Revision ChangesPath 1.10 +532 -210 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- StandardServerMBean.java 26 Apr 2002 17:40:50 - 1.9 +++ StandardServerMBean.java 27 Apr 2002 05:09:03 - 1.10 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.9 2002/04/26 17:40:50 craigmcc Exp $ - * $Revision: 1.9 $ - * $Date: 2002/04/26 17:40:50 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.10 2002/04/27 05:09:03 craigmcc Exp $ + * $Revision: 1.10 $ + * $Date: 2002/04/27 05:09:03 $ * * * @@ -64,6 +64,8 @@ package org.apache.catalina.mbeans; +import java.beans.IndexedPropertyDescriptor; +import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -76,8 +78,25 @@ import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.RuntimeOperationsException; +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.Lifecycle; +import org.apache.catalina.LifecycleListener; +import org.apache.catalina.Loader; +import org.apache.catalina.Logger; +import org.apache.catalina.Manager; +import org.apache.catalina.Pipeline; +import org.apache.catalina.Realm; import org.apache.catalina.Server; -import org.apache.catalina.core.StandardServer; +import org.apache.catalina.ServerFactory; +import org.apache.catalina.Service; +import org.apache.catalina.Store; +import org.apache.catalina.Valve; +import org.apache.catalina.net.ServerSocketFactory; +import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.modeler.BaseModelMBean; @@ -86,17 +105,74 @@ * codeorg.apache.catalina.core.StandardServer/code component./p * * @author Amy Roh - * @version $Revision: 1.9 $ $Date: 2002/04/26 17:40:50 $ + * @version $Revision: 1.10 $ $Date: 2002/04/27 05:09:03 $ */ public class StandardServerMBean extends BaseModelMBean { + +// --- Static Variables + + /** * The codeMBeanServer/code for this application. */ private static MBeanServer mserver = MBeanUtils.createServer(); +/** + * The set of class/property combinations that should strongNOT/strong + * be persisted because they are automatically calculated. + */ +private static String exceptions[][] = { +{ org.apache.catalina.core.StandardContext, configured }, +{ org.apache.catalina.core.StandardContext, publicId }, +{ org.apache.catalina.core.StandardContext, workDir }, +{ org.apache.catalina.session.StandardManager, distributable }, +{ org.apache.catalina.session.StandardManager, entropy }, +}; + + +/** + * The set of classes that represent persistable properties. + */ +private static Class persistables[] = { +String.class, +Integer.class, Integer.TYPE, +Boolean.class, Boolean.TYPE, +Byte.class, Byte.TYPE, +Character.class, Character.TYPE, +Double.class, Double.TYPE, +Float.class, Float.TYPE, +Long.class, Long.TYPE, +Short.class, Short.TYPE, +}; + + +/** + * The set of class names that should be skipped when persisting state, + * because the corresponding listeners, valves, etc. are configured + * automatically at startup time. + */ +private static String skippables[] = { +org.apache.catalina.authenticator.BasicAuthenticator, +
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml
craigmcc02/04/25 19:27:33 Modified:catalina/src/share/org/apache/catalina/mbeans StandardServerMBean.java mbeans-descriptors.xml Log: Add the beginnings of the ability to save the current Tomcat configuration to conf/server.xml. Revision ChangesPath 1.8 +237 -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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- StandardServerMBean.java 8 Mar 2002 00:42:14 - 1.7 +++ StandardServerMBean.java 26 Apr 2002 02:27:33 - 1.8 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.7 2002/03/08 00:42:14 amyroh Exp $ - * $Revision: 1.7 $ - * $Date: 2002/03/08 00:42:14 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.8 2002/04/26 02:27:33 craigmcc Exp $ + * $Revision: 1.8 $ + * $Date: 2002/04/26 02:27:33 $ * * * @@ -64,14 +64,19 @@ package org.apache.catalina.mbeans; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanAttributeInfo; import javax.management.MBeanException; +import javax.management.MBeanInfo; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.RuntimeOperationsException; import org.apache.catalina.Server; -import org.apache.catalina.Service; import org.apache.catalina.core.StandardServer; -import org.apache.catalina.core.StandardService; import org.apache.commons.modeler.BaseModelMBean; @@ -80,7 +85,7 @@ * codeorg.apache.catalina.core.StandardServer/code component./p * * @author Amy Roh - * @version $Revision: 1.7 $ $Date: 2002/03/08 00:42:14 $ + * @version $Revision: 1.8 $ $Date: 2002/04/26 02:27:33 $ */ public class StandardServerMBean extends BaseModelMBean { @@ -114,10 +119,236 @@ // - Attributes +/** + * Set the value of a specific attribute of this MBean. + * + * @param attribute The identification of the attribute to be set + * and the new value + * + * @exception AttributeNotFoundException if this attribute is not + * supported by this MBean + * @exception MBeanException if the initializer of an object + * throws an exception + * @exception ReflectionException if a Java reflection exception + * occurs when invoking the getter + */ +public void setAttribute(javax.management.Attribute attribute) +throws javax.management.AttributeNotFoundException, + MBeanException, + javax.management.ReflectionException { + +// KLUDGE - This is only here to force calling store() +// until the admin webapp calls it directly +super.setAttribute(attribute); +try { +store(); +} catch (InstanceNotFoundException e) { +throw new MBeanException(e); +} + +} // - Operations + +/** + * Write the configuration information for this entire codeServer/code + * out to the server.xml configuration file. + * + * @exception InstanceNotFoundException if the managed resource object + * cannot be found + * @exception MBeanException if the initializer of the object throws + * an exception, or persistence is not supported + * @exception RuntimeOperationsException if an exception is reported + * by the persistence mechanism + */ +public synchronized void store() throws InstanceNotFoundException, +MBeanException, RuntimeOperationsException { + +// Calculate file objects for the old and new configuration files. +String configFile = conf/server.xml; // FIXME - configurable? +File configOld = new File(configFile); +if (!configOld.isAbsolute()) { +configOld = new File(System.getProperty(catalina.base), + configFile); +} +File configNew = new File(configFile + .new); +if (!configNew.isAbsolute()) { +configNew = new File(System.getProperty(catalina.base), + configFile + .new); +