amyroh 2002/09/19 15:55:48 Modified: catalina/src/share/org/apache/catalina DefaultContext.java Loader.java Manager.java catalina/src/share/org/apache/catalina/core StandardDefaultContext.java catalina/src/share/org/apache/catalina/loader WebappLoader.java catalina/src/share/org/apache/catalina/mbeans MBeanFactory.java MBeanUtils.java ServerLifecycleListener.java catalina/src/share/org/apache/catalina/session ManagerBase.java Log: Add Loader and Manager support in DefaultContext admin. Revision Changes Path 1.5 +27 -10 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/DefaultContext.java Index: DefaultContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/DefaultContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DefaultContext.java 9 Sep 2002 23:39:03 -0000 1.4 +++ DefaultContext.java 19 Sep 2002 22:55:47 -0000 1.5 @@ -64,6 +64,7 @@ package org.apache.catalina; +import java.beans.PropertyChangeListener; import javax.naming.directory.DirContext; import org.apache.catalina.deploy.ApplicationParameter; import org.apache.catalina.deploy.ContextEjb; @@ -205,6 +206,12 @@ public void setManager(Manager manager); + /** + * Return the naming resources associated with this web application. + */ + public NamingResources getNamingResources(); + + // ------------------------------------------------------ Public Properties @@ -311,6 +318,14 @@ /** + * Add a property change listener to this component. + * + * @param listener The listener to add + */ + public void addPropertyChangeListener(PropertyChangeListener listener); + + + /** * Add a resource reference for this web application. * * @param resource New resource reference @@ -354,12 +369,6 @@ /** - * Return the naming resources associated with this web application. - */ - public NamingResources getNamingResources(); - - - /** * Return the set of application listener class names configured * for this application. */ @@ -550,6 +559,14 @@ * @param name Name of the parameter to remove */ public void removeParameter(String name); + + + /** + * Remove a property change listener from this component. + * + * @param listener The listener to remove + */ + public void removePropertyChangeListener(PropertyChangeListener listener); /** 1.6 +18 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Loader.java Index: Loader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Loader.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Loader.java 22 Jul 2001 20:13:30 -0000 1.5 +++ Loader.java 19 Sep 2002 22:55:47 -0000 1.6 @@ -126,6 +126,20 @@ /** + * Return the DefaultContext with which this Manager is associated. + */ + public DefaultContext getDefaultContext(); + + + /** + * Set the DefaultContext with which this Manager is associated. + * + * @param defaultContext The newly associated DefaultContext + */ + public void setDefaultContext(DefaultContext defaultContext); + + + /** * Return the "follow standard delegation model" flag used to configure * our ClassLoader. */ 1.6 +19 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Manager.java Index: Manager.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Manager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Manager.java 22 Jul 2001 20:13:30 -0000 1.5 +++ Manager.java 19 Sep 2002 22:55:47 -0000 1.6 @@ -110,6 +110,21 @@ /** + * Return the DefaultContext with which this Manager is associated. + */ + public DefaultContext getDefaultContext(); + + + /** + * Set the DefaultContext with which this Manager is associated. + * + * @param defaultContext The newly associated DefaultContext + */ + public void setDefaultContext(DefaultContext defaultContext); + + + + /** * Return the distributable flag for the sessions supported by * this Manager. */ 1.8 +29 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java Index: StandardDefaultContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardDefaultContext.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- StandardDefaultContext.java 30 Aug 2002 05:41:13 -0000 1.7 +++ StandardDefaultContext.java 19 Sep 2002 22:55:48 -0000 1.8 @@ -460,7 +460,7 @@ public void setLoader(Loader loader) { Loader oldLoader = this.loader; this.loader = loader; - + // Report this property change to interested listeners support.firePropertyChange("loader", oldLoader, this.loader); } @@ -657,6 +657,18 @@ } } + + + /** + * Add a property change listener to this component. + * + * @param listener The listener to add + */ + public void addPropertyChangeListener(PropertyChangeListener listener) { + + support.addPropertyChangeListener(listener); + + } /** @@ -1104,6 +1116,18 @@ synchronized (parameters) { parameters.remove(name); } + + } + + + /** + * Remove a property change listener from this component. + * + * @param listener The listener to remove + */ + public void removePropertyChangeListener(PropertyChangeListener listener) { + + support.removePropertyChangeListener(listener); } 1.29 +35 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/loader/WebappLoader.java Index: WebappLoader.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/loader/WebappLoader.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- WebappLoader.java 9 Jun 2002 01:16:11 -0000 1.28 +++ WebappLoader.java 19 Sep 2002 22:55:48 -0000 1.29 @@ -92,6 +92,7 @@ import org.apache.naming.resources.DirContextURLStreamHandlerFactory; import org.apache.catalina.Container; import org.apache.catalina.Context; +import org.apache.catalina.DefaultContext; import org.apache.catalina.Globals; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; @@ -183,6 +184,12 @@ /** + * The DefaultContext with which this Manager is associated. + */ + protected DefaultContext defaultContext = null; + + + /** * The "follow standard delegation model" flag that will be used to * configure our ClassLoader. */ @@ -341,6 +348,30 @@ /** + * Return the DefaultContext with which this Manager is associated. + */ + public DefaultContext getDefaultContext() { + + return (this.defaultContext); + + } + + + /** + * Set the DefaultContext with which this Manager is associated. + * + * @param defaultContext The newly associated DefaultContext + */ + public void setDefaultContext(DefaultContext defaultContext) { + + DefaultContext oldDefaultContext = this.defaultContext; + this.defaultContext = defaultContext; + support.firePropertyChange("defaultContext", oldDefaultContext, this.defaultContext); + + } + + + /** * Return the debugging detail level for this component. */ public int getDebug() { @@ -1357,5 +1388,3 @@ } - - 1.40 +92 -31 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java Index: MBeanFactory.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- MBeanFactory.java 18 Sep 2002 10:04:38 -0000 1.39 +++ MBeanFactory.java 19 Sep 2002 22:55:48 -0000 1.40 @@ -822,7 +822,7 @@ throws Exception { // Create a new StandardContext instance - StandardContext context = new StandardContext(); + StandardContext context = new StandardContext(); path = getPathStr(path); context.setPath(path); context.setDocBase(docBase); @@ -838,9 +838,10 @@ // Add context to the host host.addChild(context); - + // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("StandardContext"); + ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), context); return (oname.toString()); @@ -941,12 +942,28 @@ // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); + String type = pname.getKeyProperty("type"); Service service = server.findService(pname.getKeyProperty("service")); Engine engine = (Engine) service.getContainer(); - Host host = (Host) engine.findChild(pname.getKeyProperty("host")); - String pathStr = getPathStr(pname.getKeyProperty("path")); - Context context = (Context) host.findChild(pathStr); - context.setManager(manager); + if ((type != null) && (type.equals("Context"))) { + Host host = (Host) engine.findChild(pname.getKeyProperty("host")); + String pathStr = getPathStr(pname.getKeyProperty("path")); + Context context = (Context) host.findChild(pathStr); + context.setManager(manager); + } else if ((type != null) && (type.equals("DefaultContext"))) { + String hostName = pname.getKeyProperty("host"); + DefaultContext defaultContext = null; + if (hostName == null) { + defaultContext = engine.getDefaultContext(); + } else { + Host host = (Host)engine.findChild(hostName); + defaultContext = host.getDefaultContext(); + } + if (defaultContext != null ){ + manager.setDefaultContext(defaultContext); + defaultContext.setManager(manager); + } + } // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("StandardManager"); @@ -1123,12 +1140,28 @@ // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); + String type = pname.getKeyProperty("type"); Service service = server.findService(pname.getKeyProperty("service")); Engine engine = (Engine) service.getContainer(); - Host host = (Host) engine.findChild(pname.getKeyProperty("host")); - String pathStr = getPathStr(pname.getKeyProperty("path")); - Context context = (Context) host.findChild(pathStr); - context.setLoader(loader); + if ((type != null) && (type.equals("Context"))) { + Host host = (Host) engine.findChild(pname.getKeyProperty("host")); + String pathStr = getPathStr(pname.getKeyProperty("path")); + Context context = (Context) host.findChild(pathStr); + context.setLoader(loader); + } else if ((type != null) && (type.equals("DefaultContext"))) { + String hostName = pname.getKeyProperty("host"); + DefaultContext defaultContext = null; + if (hostName == null) { + defaultContext = engine.getDefaultContext(); + } else { + Host host = (Host)engine.findChild(hostName); + defaultContext = host.getDefaultContext(); + } + if (defaultContext != null ){ + loader.setDefaultContext(defaultContext); + defaultContext.setLoader(loader); + } + } // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("WebappLoader"); @@ -1311,18 +1344,32 @@ // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); + String type = oname.getKeyProperty("type"); String serviceName = oname.getKeyProperty("service"); - String hostName = oname.getKeyProperty("host"); - String contextName = getPathStr(oname.getKeyProperty("path")); Server server = ServerFactory.getServer(); Service service = server.findService(serviceName); - Engine engine = (Engine) service.getContainer(); - Host host = (Host) engine.findChild(hostName); - Context context = (Context) host.findChild(contextName); - - // Remove this component from its parent component - context.setLoader(null); - + Engine engine = (Engine) service.getContainer(); + String hostName = oname.getKeyProperty("host"); + if ((type != null) && (type.equals("Loader"))) { + String contextName = getPathStr(oname.getKeyProperty("path")); + Host host = (Host) engine.findChild(hostName); + Context context = (Context) host.findChild(contextName); + // Remove this component from its parent component + context.setLoader(null); + } else if ((type != null) && (type.equals("DefaultLoader"))) { + DefaultContext defaultContext = null; + if (hostName == null) { + defaultContext = engine.getDefaultContext(); + } else { + Host host = (Host) engine.findChild(hostName); + defaultContext = host.getDefaultContext(); + } + if (defaultContext != null) { + // Remove this component from its parent component + defaultContext.setLoader(null); + } + } + } @@ -1337,17 +1384,31 @@ // Acquire a reference to the component to be removed ObjectName oname = new ObjectName(name); + String type = oname.getKeyProperty("type"); String serviceName = oname.getKeyProperty("service"); - String hostName = oname.getKeyProperty("host"); - String contextName = getPathStr(oname.getKeyProperty("path")); Server server = ServerFactory.getServer(); Service service = server.findService(serviceName); - Engine engine = (Engine) service.getContainer(); - Host host = (Host) engine.findChild(hostName); - Context context = (Context) host.findChild(contextName); - - // Remove this component from its parent component - context.setManager(null); + Engine engine = (Engine) service.getContainer(); + String hostName = oname.getKeyProperty("host"); + if ((type != null) && (type.equals("Manager"))) { + String contextName = getPathStr(oname.getKeyProperty("path")); + Host host = (Host) engine.findChild(hostName); + Context context = (Context) host.findChild(contextName); + // Remove this component from its parent component + context.setManager(null); + } else if ((type != null) && (type.equals("DefaultManager"))) { + DefaultContext defaultContext = null; + if (hostName == null) { + defaultContext = engine.getDefaultContext(); + } else { + Host host = (Host) engine.findChild(hostName); + defaultContext = host.getDefaultContext(); + } + if (defaultContext != null) { + // Remove this component from its parent component + defaultContext.setManager(null); + } + } } 1.44 +45 -16 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.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- MBeanUtils.java 11 Sep 2002 14:19:33 -0000 1.43 +++ MBeanUtils.java 19 Sep 2002 22:55:48 -0000 1.44 @@ -470,8 +470,8 @@ */ public static ModelMBean createMBean(Loader loader) throws Exception { - - String mname = createManagedName(loader); + + String mname = createManagedName(loader); ManagedBean managed = registry.findManagedBean(mname); if (managed == null) { Exception e = new Exception("ManagedBean is not found with "+mname); @@ -483,8 +483,7 @@ ModelMBean mbean = managed.createMBean(loader); ObjectName oname = createObjectName(domain, loader); mserver.registerMBean(mbean, oname); - return (mbean); - + return (mbean); } /** @@ -944,14 +943,14 @@ Host host = (Host) container; Service service = ((Engine)host.getParent()).getService(); name = new ObjectName(domain + ":type=Environment" + - ",resourcetype=DefaultContext,host=" + host.getName() + + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",service=" + service.getName() + ",name=" + environment.getName()); } else if (container instanceof Engine) { Engine engine = (Engine) container; Service service = engine.getService(); name = new ObjectName(domain + ":type=Environment" + - ",resourcetype=DefaultContext,service=" + + ",resourcetype=ServiceDefaultContext,service=" + service.getName() + ",name=" + environment.getName()); } } @@ -1001,7 +1000,7 @@ Host host = (Host) container; Service service = ((Engine)host.getParent()).getService(); name = new ObjectName(domain + ":type=Resource" + - ",resourcetype=DefaultContext,host=" + host.getName() + + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",service=" + service.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); @@ -1009,7 +1008,7 @@ Engine engine = (Engine) container; Service service = engine.getService(); name = new ObjectName(domain + ":type=Resource" + - ",resourcetype=DefaultContext,service=" + service.getName() + + ",resourcetype=ServiceDefaultContext,service=" + service.getName() + ",class=" + resource.getType() + ",name=" + encodedResourceName); } @@ -1060,7 +1059,7 @@ Host host = (Host) container; Service service = ((Engine)host.getParent()).getService(); name = new ObjectName(domain + ":type=ResourceLink" + - ",resourcetype=DefaultContext,host=" + host.getName() + + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",service=" + service.getName() + ",class=" + resourceLink.getType() + ",name=" + encodedResourceLinkName); @@ -1068,7 +1067,7 @@ Engine engine = (Engine) container; Service service = engine.getService(); name = new ObjectName(domain + ":type=ResourceLink" + - ",resourcetype=DefaultContext,service=" + service.getName() + + ",resourcetype=ServiceDefaultContext,service=" + service.getName() + ",class=" + resourceLink.getType() + ",name=" + encodedResourceLinkName); } @@ -1215,6 +1214,21 @@ name = new ObjectName(domain + ":type=Loader,path=" + path + ",host=" + host.getName() + ",service=" + service.getName()); + } else if (container == null) { + DefaultContext defaultContext = loader.getDefaultContext(); + if (defaultContext != null) { + Container parent = defaultContext.getParent(); + if (parent instanceof Engine) { + Service service = ((Engine)parent).getService(); + name = new ObjectName(domain + ":type=DefaultLoader,service=" + + service.getName()); + } else if (parent instanceof Host) { + Engine engine = (Engine) parent.getParent(); + Service service = engine.getService(); + name = new ObjectName(domain + ":type=DefaultLoader,host=" + + parent.getName() + ",service=" + service.getName()); + } + } } return (name); @@ -1303,6 +1317,21 @@ name = new ObjectName(domain + ":type=Manager,path=" + path + ",host=" + host.getName() + ",service=" + service.getName()); + } else if (container == null) { + DefaultContext defaultContext = manager.getDefaultContext(); + if (defaultContext != null) { + Container parent = defaultContext.getParent(); + if (parent instanceof Engine) { + Service service = ((Engine)parent).getService(); + name = new ObjectName(domain + ":type=DefaultManager,service=" + + service.getName()); + } else if (parent instanceof Host) { + Engine engine = (Engine) parent.getParent(); + Service service = engine.getService(); + name = new ObjectName(domain + ":type=DefaultManager,host=" + + parent.getName() + ",service=" + service.getName()); + } + } } return (name); @@ -1345,13 +1374,13 @@ Host host = (Host) container; Service service = ((Engine)host.getParent()).getService(); name = new ObjectName(domain + ":type=NamingResources" + - ",resourcetype=DefaultContext,host=" + host.getName() + + ",resourcetype=HostDefaultContext,host=" + host.getName() + ",service=" + service.getName()); } else if (container instanceof Engine) { Engine engine = (Engine) container; Service service = engine.getService(); name = new ObjectName(domain + ":type=NamingResources" + - ",resourcetype=DefaultContext" + + ",resourcetype=ServiceDefaultContext" + ",service=" + service.getName()); } } 1.34 +94 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java Index: ServerLifecycleListener.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- ServerLifecycleListener.java 13 Sep 2002 01:35:22 -0000 1.33 +++ ServerLifecycleListener.java 19 Sep 2002 22:55:48 -0000 1.34 @@ -265,7 +265,7 @@ } catch (Exception e) { log("Exception handling Container property change", e); } - } else if (event.getSource() instanceof NamingResources) { + } else if (event.getSource() instanceof NamingResources) { try { processNamingResourcesPropertyChange ((NamingResources) event.getSource(), @@ -507,7 +507,8 @@ if (debug >= 4) log("Creating MBean for DefaultContext " + dcontext); MBeanUtils.createMBean(dcontext); - + dcontext.addPropertyChangeListener(this); + // Create the MBeans for the associated nested components Loader dLoader = dcontext.getLoader(); if (dLoader != null) { @@ -981,6 +982,7 @@ if (debug >= 4) log("Destroying MBean for Context " + dcontext); MBeanUtils.destroyMBean(dcontext); + dcontext.removePropertyChangeListener(this); } @@ -1385,6 +1387,92 @@ } + /** + * Process a property change event on a DefaultContext. + * + * @param defaultContext The DefaultContext on which this event occurred + * @param propertyName The name of the property that changed + * @param oldValue The previous value (may be <code>null</code>) + * @param newValue The new value (may be <code>null</code>) + * + * @exception Exception if an exception is thrown + */ + protected void processDefaultContextPropertyChange(DefaultContext defaultContext, + String propertyName, + Object oldValue, + Object newValue) + throws Exception { + + if (debug >= 6) { + log("propertyChange[defaultContext=" + defaultContext + + ",propertyName=" + propertyName + + ",oldValue=" + oldValue + + ",newValue=" + newValue + "]"); + } + if ("loader".equals(propertyName)) { + if (oldValue != null) { + if (debug >= 5) { + log("Removing MBean for Loader " + oldValue); + } + MBeanUtils.destroyMBean((Loader) oldValue); + } + if (newValue != null) { + if (debug >= 5) { + log("Creating MBean for Loader " + newValue); + } + MBeanUtils.createMBean((Loader) newValue); + } + } else if ("logger".equals(propertyName)) { + if (oldValue != null) { + if (debug >= 5) { + log("Removing MBean for Logger " + oldValue); + } + MBeanUtils.destroyMBean((Logger) oldValue); + } + if (newValue != null) { + if (debug >= 5) { + log("Creating MBean for Logger " + newValue); + } + MBeanUtils.createMBean((Logger) newValue); + } + } else if ("manager".equals(propertyName)) { + if (oldValue != null) { + if (debug >= 5) { + log("Removing MBean for Manager " + oldValue); + } + MBeanUtils.destroyMBean((Manager) oldValue); + } + if (newValue != null) { + if (debug >= 5) { + log("Creating MBean for Manager " + newValue); + } + MBeanUtils.createMBean((Manager) newValue); + } + } else if ("realm".equals(propertyName)) { + if (oldValue != null) { + if (debug >= 5) { + log("Removing MBean for Realm " + oldValue); + } + MBeanUtils.destroyMBean((Realm) oldValue); + } + if (newValue != null) { + if (debug >= 5) { + log("Creating MBean for Realm " + newValue); + } + MBeanUtils.createMBean((Realm) newValue); + } + } else if ("service".equals(propertyName)) { + if (oldValue != null) { + destroyMBeans((Service) oldValue); + } + if (newValue != null) { + createMBeans((Service) newValue); + } + } + + } + + /** * Process the removal of a child Container from a parent Container. * 1.12 +35 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/ManagerBase.java Index: ManagerBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/session/ManagerBase.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- ManagerBase.java 14 Jan 2002 23:38:03 -0000 1.11 +++ ManagerBase.java 19 Sep 2002 22:55:48 -0000 1.12 @@ -74,6 +74,7 @@ import java.util.HashMap; import java.util.Random; import org.apache.catalina.Container; +import org.apache.catalina.DefaultContext; import org.apache.catalina.Engine; import org.apache.catalina.Logger; import org.apache.catalina.Manager; @@ -131,6 +132,12 @@ /** + * The DefaultContext with which this Manager is associated. + */ + protected DefaultContext defaultContext = null; + + + /** * Return the MessageDigest implementation to be used when * creating session identifiers. */ @@ -262,6 +269,30 @@ /** + * Return the DefaultContext with which this Manager is associated. + */ + public DefaultContext getDefaultContext() { + + return (this.defaultContext); + + } + + + /** + * Set the DefaultContext with which this Manager is associated. + * + * @param defaultContext The newly associated DefaultContext + */ + public void setDefaultContext(DefaultContext defaultContext) { + + DefaultContext oldDefaultContext = this.defaultContext; + this.defaultContext = defaultContext; + support.firePropertyChange("defaultContext", oldDefaultContext, this.defaultContext); + + } + + + /** * Return the debugging detail level for this component. */ public int getDebug() { @@ -762,4 +793,3 @@ } -
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>