costin 2003/03/20 10:28:29 Modified: catalina/src/share/org/apache/catalina/core ContainerBase.java StandardContext.java StandardHost.java StandardPipeline.java StandardWrapper.java StandardWrapperValve.java mbeans-descriptors.xml Log: Fix the build - the dependencies don't seem to work very well.. Removed some duplicated methods and unused fields, moved more to super, more work on clean stop and restart. Revision Changes Path 1.12 +78 -6 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java Index: ContainerBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ContainerBase.java 20 Mar 2003 15:55:28 -0000 1.11 +++ ContainerBase.java 20 Mar 2003 18:28:28 -0000 1.12 @@ -75,6 +75,7 @@ import javax.management.ObjectName; import javax.management.MBeanRegistration; import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; import org.apache.naming.resources.ProxyDirContext; import org.apache.catalina.Cluster; @@ -93,6 +94,7 @@ import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.Valve; +import org.apache.catalina.startup.ContextConfig; import org.apache.catalina.logger.LoggerBase; import org.apache.catalina.session.StandardManager; import org.apache.catalina.valves.ValveBase; @@ -347,7 +349,9 @@ * the corresponding version number, in the format * <code><description>/<version></code>. */ - public abstract String getInfo(); + public String getInfo() { + return this.getClass().getName(); + } /** @@ -1219,9 +1223,11 @@ try { ObjectName vname=((ValveBase)valve).createObjectName(getDomain(), this.getObjectName()); - ((ValveBase)valve).setObjectName(vname); - Registry.getRegistry().registerComponent(valve, vname, valve.getClass().getName()); - ((ValveBase)valve).setController(oname); + if( vname != null ) { + ((ValveBase)valve).setObjectName(vname); + Registry.getRegistry().registerComponent(valve, vname, valve.getClass().getName()); + ((ValveBase)valve).setController(oname); + } } catch( Throwable t ) { log.info( "Can't register valve " + valve , t ); } @@ -1335,11 +1341,77 @@ ((Lifecycle) loader).stop(); } + if( logger instanceof LoggerBase ) { + LoggerBase lb=(LoggerBase)logger; + if( lb.getObjectName()==null ) { + ObjectName lname=lb.createObjectName(); + try { + Registry.getRegistry().registerComponent(lb, lname, null); + } catch( Exception ex ) { + log.error( "Can't register logger " + lname, ex); + } + } + } + + // + Valve valves[]=getValves(); + for( int i=0; i<valves.length; i++ ) { + Valve valve=valves[i]; + if( valve instanceof ValveBase && + ((ValveBase)valve).getObjectName()!=null ) { + Registry.getRegistry().unregisterComponent(((ValveBase)valve).getObjectName()); + } + } + // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null); } + /** Init method, part of the MBean lifecycle. + * If the container was added via JMX, it'll register itself with the + * parent, using the ObjectName conventions to locate the parent. + * + * If the container was added directly and it doesn't have an ObjectName, + * it'll create a name and register itself with the JMX console. On destroy(), + * the object will unregister. + * + * @throws Exception + */ + public void init() throws Exception { + + if( this.getParent() == null ) { + // "Life" update + ObjectName parentName=getParentName(); + + if( parentName != null && + ! mserver.isRegistered(parentName)) + { + mserver.invoke(parentName, "addChild", new Object[] { this }, + new String[] {"org.apache.catalina.Container"}); + } + } + } + + public ObjectName getParentName() throws MalformedObjectNameException { + return null; + } + + public void destroy() throws Exception { + if( started ) { + stop(); + } + if (parent != null) { + parent.removeChild(this); + } + + // Stop our child containers, if any + Container children[] = findChildren(); + for (int i = 0; i < children.length; i++) { + removeChild(children[i]); + } + + } // ------------------------------------------------------- Pipeline Methods @@ -1368,8 +1440,8 @@ fireContainerEvent(ADD_VALVE_EVENT, valve); } - public ObjectName[] getValveNames() { - return ((StandardPipeline)pipeline).getValveNames(); + public ObjectName[] getValveObjectNames() { + return ((StandardPipeline)pipeline).getValveObjectNames(); } /** 1.29 +25 -28 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java Index: StandardContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- StandardContext.java 17 Mar 2003 07:26:40 -0000 1.28 +++ StandardContext.java 20 Mar 2003 18:28:28 -0000 1.29 @@ -4768,18 +4768,38 @@ log.info( "Already configured" ); return; } + ObjectName parentName=getParentName(); + + log.info("Adding to " + parentName ); + + if( ! mserver.isRegistered(parentName)) { + log.info("No host, creating one "); + StandardHost host=new StandardHost(); + host.setName(hostName); + Registry.getRegistry().registerComponent(host, parentName, null); + mserver.invoke(parentName, "init", new Object[] {}, new String[] {} ); + } + ContextConfig config = new ContextConfig(); + this.addLifecycleListener(config); + + super.init(); + } + + String hostName; + + public ObjectName getParentName() throws MalformedObjectNameException { // "Life" update String path=oname.getKeyProperty("name"); if( path == null ) { log.error( "No name attribute " +name ); - return; + return null; } if( ! path.startsWith( "//")) { log.error("Invalid name " + name); } path=path.substring(2); int delim=path.indexOf( "/" ); - String hostName="localhost"; // Should be default... + hostName="localhost"; // Should be default... if( delim > 0 ) { hostName=path.substring(0, delim); this.setName( path.substring(delim)); @@ -4790,32 +4810,9 @@ // XXX The service and domain should be the same. ObjectName parentName=new ObjectName( domain + ":" + "type=Host,host=" + hostName); - log.info("Adding to " + parentName ); - - if( ! mserver.isRegistered(parentName)) { - log.info("No host, creating one "); - StandardHost host=new StandardHost(); - host.setName(hostName); - Registry.getRegistry().registerComponent(host, parentName, null); - mserver.invoke(parentName, "init", new Object[] {}, new String[] {} ); - } - ContextConfig config = new ContextConfig(); - this.addLifecycleListener(config); - - mserver.invoke(parentName, "addChild", new Object[] { this }, - new String[] {"org.apache.catalina.Container"}); - - } - - public void destroy() throws Exception { - if( started ) { - stop(); - } - if (parent != null) { - parent.removeChild(this); - } + return parentName; } - + public void create() throws Exception{ init(); } 1.7 +1 -13 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java Index: StandardHost.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- StandardHost.java 19 Mar 2003 07:24:40 -0000 1.6 +++ StandardHost.java 20 Mar 2003 18:28:28 -0000 1.7 @@ -1007,18 +1007,6 @@ } - public ObjectName[] getValveObjectNames() - throws Exception - { - Valve [] valves = this.getValves(); - ObjectName [] mbeanNames = new ObjectName[valves.length]; - for (int i = 0; i < valves.length; i++) { - mbeanNames[i] = ((ValveBase)valves[i]).getObjectName(); - } - - return mbeanNames; - } - public String[] getAliases() { return aliases; } 1.4 +1 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardPipeline.java Index: StandardPipeline.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardPipeline.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StandardPipeline.java 20 Mar 2003 15:56:21 -0000 1.3 +++ StandardPipeline.java 20 Mar 2003 18:28:28 -0000 1.4 @@ -466,7 +466,7 @@ } - public ObjectName[] getValveNames() { + public ObjectName[] getValveObjectNames() { ObjectName oname[]=new ObjectName[valves.length + 1]; for( int i=0; i<valves.length; i++ ) { if( valves[i] instanceof ValveBase ) 1.19 +23 -11 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Index: StandardWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- StandardWrapper.java 17 Mar 2003 07:36:59 -0000 1.18 +++ StandardWrapper.java 20 Mar 2003 18:28:28 -0000 1.19 @@ -81,6 +81,7 @@ import javax.servlet.ServletResponse; import javax.servlet.SingleThreadModel; import javax.servlet.UnavailableException; +import javax.management.ObjectName; import org.apache.catalina.Container; import org.apache.catalina.ContainerServlet; @@ -261,7 +262,7 @@ // To support jmx attributes private StandardWrapperValve swValve; private long loadTime=0; - private long classLoadTime=0; + private int classLoadTime=0; // ------------------------------------------------------------- Properties @@ -1004,7 +1005,7 @@ ((ContainerServlet) servlet).setWrapper(this); } - classLoadTime=System.currentTimeMillis() -t1; + classLoadTime=(int) (System.currentTimeMillis() -t1); // Call the initialization method of this servlet try { instanceSupport.fireInstanceEvent(InstanceEvent.BEFORE_INIT_EVENT, @@ -1084,8 +1085,6 @@ } } } - if( oname != null ) - registerJMX((StandardContext)getParent()); return servlet; } @@ -1405,6 +1404,11 @@ public void setLoadTime(long loadTime) { this.loadTime = loadTime; } + + public int getClassLoadTime() { + return classLoadTime; + } + // -------------------------------------------------------- Package Methods @@ -1499,6 +1503,9 @@ // Start up this component super.start(); + if( oname != null ) + registerJMX((StandardContext)getParent()); + // Load and initialize an instance of this servlet if requested // MOVED TO StandardContext START() METHOD @@ -1528,6 +1535,9 @@ // Shut down this component super.stop(); + if( oname != null ) { + Registry.getRegistry().unregisterComponent(oname); + } } protected void registerJMX(StandardContext ctx) { @@ -1541,13 +1551,15 @@ String hostName=ctx.getParent().getName(); String webMod= "//" + ((hostName==null)? "DEFAULT" :hostName ) + (("".equals(parentName) ) ? "/" : parentName ); - String oname="j2eeType=Servlet,name=" + name + ",WebModule=" + + String onameStr=ctx.getDomain() + + ":j2eeType=Servlet,name=" + name + ",WebModule=" + webMod + ",J2EEApplication=" + ctx.getJ2EEApplication() + ",J2EEServer=" + ctx.getJ2EEServer(); + + oname=new ObjectName(onameStr); - Registry.getRegistry().registerComponent(this, - ctx.getDomain(), "Servlet", oname); + Registry.getRegistry().registerComponent(this, oname, null ); } catch( Exception ex ) { log.info("Error registering servlet with jmx " + this); } 1.13 +29 -116 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java Index: StandardWrapperValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- StandardWrapperValve.java 12 Feb 2003 11:04:59 -0000 1.12 +++ StandardWrapperValve.java 20 Mar 2003 18:28:28 -0000 1.13 @@ -1,8 +1,4 @@ /* - * $Header$ - * $Revision$ - * $Date$ - * * ==================================================================== * * The Apache Software License, Version 1.1 @@ -66,39 +62,28 @@ import java.io.IOException; -import java.io.PrintWriter; -import javax.servlet.FilterConfig; -import javax.servlet.RequestDispatcher; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; import javax.servlet.Servlet; -import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.UnavailableException; -import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.apache.tomcat.util.buf.MessageBytes; - -import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Globals; import org.apache.catalina.HttpRequest; -import org.apache.catalina.HttpResponse; import org.apache.catalina.Logger; import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.ValveContext; -import org.apache.catalina.Wrapper; -import org.apache.catalina.deploy.ErrorPage; import org.apache.catalina.deploy.FilterDef; -import org.apache.catalina.deploy.FilterMap; -import org.apache.catalina.util.InstanceSupport; -import org.apache.catalina.util.RequestUtil; import org.apache.catalina.util.StringManager; import org.apache.catalina.valves.ValveBase; +import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** @@ -110,22 +95,16 @@ */ final class StandardWrapperValve - extends ValveBase { - + extends ValveBase + { + private static Log log = LogFactory.getLog(StandardWrapperValve.class); // ----------------------------------------------------- Instance Variables - - /** - * The debugging detail level for this component. - */ - private int debug = 0; - - /** * The filter definition for our container-provided filter. */ - private FilterDef filterDef = null; + //private FilterDef filterDef = null; // Some JMX statistics. This vavle is associated with a StandardWrapper. // We exponse the StandardWrapper as JMX ( j2eeType=Servlet ). The fields @@ -135,34 +114,12 @@ private int requestCount; private int errorCount; - - /** - * The descriptive information related to this implementation. - */ - private static final String info = - "org.apache.catalina.core.StandardWrapperValve/1.0"; - - /** * The string manager for this package. */ private static final StringManager sm = StringManager.getManager(Constants.Package); - - // ------------------------------------------------------------- Properties - - - /** - * Return descriptive information about this Valve implementation. - */ - public String getInfo() { - - return (info); - - } - - // --------------------------------------------------------- Public Methods @@ -210,7 +167,7 @@ // Check for the servlet being marked unavailable if (!unavailable && wrapper.isUnavailable()) { - log(sm.getString("standardWrapper.isUnavailable", + log.info(sm.getString("standardWrapper.isUnavailable", wrapper.getName())); if (hres == null) { ; // NOTE - Not much we can do generically @@ -236,13 +193,13 @@ servlet = wrapper.allocate(); } } catch (ServletException e) { - log(sm.getString("standardWrapper.allocateException", + log.error(sm.getString("standardWrapper.allocateException", wrapper.getName()), e); throwable = e; exception(request, response, e); servlet = null; } catch (Throwable e) { - log(sm.getString("standardWrapper.allocateException", + log.error(sm.getString("standardWrapper.allocateException", wrapper.getName()), e); throwable = e; exception(request, response, e); @@ -254,12 +211,12 @@ response.sendAcknowledgement(); } catch (IOException e) { sreq.removeAttribute(Globals.JSP_FILE_ATTR); - log(sm.getString("standardWrapper.acknowledgeException", + log.error(sm.getString("standardWrapper.acknowledgeException", wrapper.getName()), e); throwable = e; exception(request, response, e); } catch (Throwable e) { - log(sm.getString("standardWrapper.acknowledgeException", + log.error(sm.getString("standardWrapper.acknowledgeException", wrapper.getName()), e); throwable = e; exception(request, response, e); @@ -296,13 +253,13 @@ sreq.removeAttribute(Globals.JSP_FILE_ATTR); } catch (IOException e) { sreq.removeAttribute(Globals.JSP_FILE_ATTR); - log(sm.getString("standardWrapper.serviceException", + log.error(sm.getString("standardWrapper.serviceException", wrapper.getName()), e); throwable = e; exception(request, response, e); } catch (UnavailableException e) { sreq.removeAttribute(Globals.JSP_FILE_ATTR); - log(sm.getString("standardWrapper.serviceException", + log.error(sm.getString("standardWrapper.serviceException", wrapper.getName()), e); // throwable = e; // exception(request, response, e); @@ -322,13 +279,13 @@ // do not want to do exception(request, response, e) processing } catch (ServletException e) { sreq.removeAttribute(Globals.JSP_FILE_ATTR); - log(sm.getString("standardWrapper.serviceException", + log.error(sm.getString("standardWrapper.serviceException", wrapper.getName()), e); throwable = e; exception(request, response, e); } catch (Throwable e) { sreq.removeAttribute(Globals.JSP_FILE_ATTR); - log(sm.getString("standardWrapper.serviceException", + log.error(sm.getString("standardWrapper.serviceException", wrapper.getName()), e); throwable = e; exception(request, response, e); @@ -339,7 +296,7 @@ if (filterChain != null) filterChain.release(); } catch (Throwable e) { - log(sm.getString("standardWrapper.releaseFilters", + log.error(sm.getString("standardWrapper.releaseFilters", wrapper.getName()), e); if (throwable == null) { throwable = e; @@ -353,7 +310,7 @@ wrapper.deallocate(servlet); } } catch (Throwable e) { - log(sm.getString("standardWrapper.deallocateException", + log.error(sm.getString("standardWrapper.deallocateException", wrapper.getName()), e); if (throwable == null) { throwable = e; @@ -369,7 +326,7 @@ wrapper.unload(); } } catch (Throwable e) { - log(sm.getString("standardWrapper.unloadException", + log.error(sm.getString("standardWrapper.unloadException", wrapper.getName()), e); if (throwable == null) { throwable = e; @@ -411,57 +368,6 @@ } - - /** - * Log a message on the Logger associated with our Container (if any) - * - * @param message Message to be logged - */ - private void log(String message) { - - Logger logger = null; - if (container != null) - logger = container.getLogger(); - if (logger != null) - logger.log("StandardWrapperValve[" + container.getName() + "]: " - + message); - else { - String containerName = null; - if (container != null) - containerName = container.getName(); - System.out.println("StandardWrapperValve[" + containerName - + "]: " + message); - } - - } - - - /** - * Log a message on the Logger associated with our Container (if any) - * - * @param message Message to be logged - * @param throwable Associated exception - */ - private void log(String message, Throwable throwable) { - - Logger logger = null; - if (container != null) - logger = container.getLogger(); - if (logger != null) - logger.log("StandardWrapperValve[" + container.getName() + "]: " - + message, throwable); - else { - String containerName = null; - if (container != null) - containerName = container.getName(); - System.out.println("StandardWrapperValve[" + containerName - + "]: " + message); - System.out.println("" + throwable); - throwable.printStackTrace(System.out); - } - - } - public long getProcessingTime() { return processingTime; } @@ -494,4 +400,11 @@ this.errorCount = errorCount; } + // Don't register in JMX + + public ObjectName createObjectName(String domain, ObjectName parent) + throws MalformedObjectNameException + { + return null; + } } 1.4 +2 -7 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/mbeans-descriptors.xml Index: mbeans-descriptors.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/mbeans-descriptors.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- mbeans-descriptors.xml 20 Mar 2003 15:56:40 -0000 1.3 +++ mbeans-descriptors.xml 20 Mar 2003 18:28:28 -0000 1.4 @@ -119,7 +119,7 @@ description="The document root for this web application" type="java.lang.String"/> - <attribute name="valveNames" + <attribute name="valveObjectNames" description="ObjectNames for the valves associated with this container" type="[Ljavax.management.ObjectName;" writeable="false"/> @@ -318,7 +318,7 @@ description="Route used for load balancing" type="java.lang.String"/> - <attribute name="valveNames" + <attribute name="valveObjectNames" description="ObjectNames for the valves associated with this container" type="[Ljavax.management.ObjectName;" writeable="false"/> @@ -428,11 +428,6 @@ description="Return the MBean ObjectNames of the Valves associated with this Host" type="[Ljavax.management.ObjectName;"/> - <attribute name="valveNames" - description="ObjectNames for the valves associated with this container" - type="[Ljavax.management.ObjectName;" - writeable="false"/> - <operation name="addAlias" description="Add an alias name that should be mapped to this Host" impact="ACTION"
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]