amyroh 2003/03/26 19:06:40 Modified: catalina/src/share/org/apache/catalina/core ContainerBase.java StandardPipeline.java StandardService.java catalina/src/share/org/apache/catalina/logger FileLogger.java LoggerBase.java catalina/src/share/org/apache/catalina/mbeans MBeanFactory.java catalina/src/share/org/apache/catalina/realm RealmBase.java catalina/src/share/org/apache/catalina/valves ValveBase.java Log: Add deregistration code for container, service, valve/logger dynamic registration. Use getObjectName() instead of MBeanUtils for most of cases. Revision Changes Path 1.17 +12 -2 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ContainerBase.java 26 Mar 2003 19:20:29 -0000 1.16 +++ ContainerBase.java 27 Mar 2003 03:06:39 -0000 1.17 @@ -1322,6 +1322,16 @@ } } + // unregister this component + if( oname != null ) { + try { + Registry.getRegistry().unregisterComponent(oname); + log.info("unregistering " + oname); + } catch( Throwable t ) { + log.error("Error unregistering ", t ); + } + } + // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null); @@ -1667,11 +1677,11 @@ host=context.getParent(); servlet=container; } - if( host!=null ) suffix.append(",host=").append( host.getName() ); if( context!=null ) { String path=((StandardContext)context).getPath(); - suffix.append(",path=").append((path=="") ? "/" : path); + suffix.append(",path=").append((path.equals("")) ? "/" : path); } + if( host!=null ) suffix.append(",host=").append( host.getName() ); if( servlet != null ) { String name=container.getName(); suffix.append(",servlet="); 1.6 +7 -3 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StandardPipeline.java 26 Mar 2003 19:20:29 -0000 1.5 +++ StandardPipeline.java 27 Mar 2003 03:06:39 -0000 1.6 @@ -486,6 +486,8 @@ results[valves.length] = valve; valves = results; } + // register the newly added valve + registerValve(valve); } @@ -601,6 +603,8 @@ log.error("StandardPipeline.removeValve: stop: ", e); } } + // unregister the removed valave + unregisterValve(valve); } 1.5 +14 -4 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardService.java Index: StandardService.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardService.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- StandardService.java 21 Mar 2003 08:16:20 -0000 1.4 +++ StandardService.java 27 Mar 2003 03:06:39 -0000 1.5 @@ -582,6 +582,16 @@ } } } + + // unregister this service + if( oname!=null ) { + try { + Registry.getRegistry().unregisterComponent(oname); + log.info("unregistering " + oname); + } catch (Exception e) { + log.error("Error unregistering ",e); + } + } // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null); 1.2 +9 -51 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/FileLogger.java Index: FileLogger.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/FileLogger.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- FileLogger.java 18 Jul 2002 16:48:01 -0000 1.1 +++ FileLogger.java 27 Mar 2003 03:06:39 -0000 1.2 @@ -70,10 +70,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.sql.Timestamp; -import org.apache.catalina.Lifecycle; -import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; import org.apache.catalina.util.LifecycleSupport; import org.apache.catalina.util.StringManager; @@ -88,8 +85,7 @@ */ public class FileLogger - extends LoggerBase - implements Lifecycle { + extends LoggerBase { // ----------------------------------------------------- Instance Variables @@ -116,12 +112,6 @@ /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The prefix that is added to log file filenames. */ private String prefix = "catalina."; @@ -344,41 +334,6 @@ /** - * Add a lifecycle event listener to this component. - * - * @param listener The listener to add - */ - public void addLifecycleListener(LifecycleListener listener) { - - lifecycle.addLifecycleListener(listener); - - } - - - /** - * Get the lifecycle listeners associated with this lifecycle. If this - * Lifecycle has no listeners registered, a zero-length array is returned. - */ - public LifecycleListener[] findLifecycleListeners() { - - return lifecycle.findLifecycleListeners(); - - } - - - /** - * Remove a lifecycle event listener from this component. - * - * @param listener The listener to add - */ - public void removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - - /** * Prepare for the beginning of active use of the public methods of this * component. This method should be called after <code>configure()</code>, * and before any of the public methods of the component are utilized. @@ -394,6 +349,8 @@ (sm.getString("fileLogger.alreadyStarted")); lifecycle.fireLifecycleEvent(START_EVENT, null); started = true; + + super.start(); } @@ -416,9 +373,10 @@ started = false; close(); + + super.stop(); } } - 1.3 +117 -14 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/LoggerBase.java Index: LoggerBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/LoggerBase.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- LoggerBase.java 19 Mar 2003 07:27:57 -0000 1.2 +++ LoggerBase.java 27 Mar 2003 03:06:39 -0000 1.3 @@ -75,14 +75,18 @@ import javax.management.MBeanServer; import javax.management.MBeanRegistration; import org.apache.catalina.Container; -import org.apache.catalina.LifecycleException; import org.apache.catalina.Logger; import org.apache.catalina.Lifecycle; +import org.apache.catalina.LifecycleEvent; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleListener; import org.apache.catalina.core.StandardEngine; import org.apache.catalina.core.StandardHost; import org.apache.catalina.core.StandardContext; +import org.apache.catalina.util.LifecycleSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.commons.modeler.Registry; /** @@ -95,7 +99,7 @@ */ public class LoggerBase - implements Logger, MBeanRegistration + implements Lifecycle, Logger, MBeanRegistration { private static Log log = LogFactory.getLog(LoggerBase.class); @@ -122,6 +126,12 @@ /** + * The lifecycle event support for this component. + */ + protected LifecycleSupport lifecycle = new LifecycleSupport(this); + + + /** * The property change support for this component. */ protected PropertyChangeSupport support = new PropertyChangeSupport(this); @@ -361,7 +371,7 @@ support.removePropertyChangeListener(listener); } - + protected String domain; protected String host; protected String path; @@ -380,20 +390,23 @@ public ObjectName getObjectName() { return oname; } - + public String getDomain() { return domain; } - + public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname=name; mserver=server; + // FIXME null pointer exception + if (name == null) { + return null; + } domain=name.getDomain(); - host=name.getKeyProperty("host"); path=name.getKeyProperty("path"); - + log("preRegister with "+name); if( container== null ) { // Register with the parent try { @@ -414,7 +427,7 @@ } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } - } + } return name; } @@ -437,6 +450,7 @@ } public ObjectName createObjectName() { + log("createObjectName with "+container); // register try { StandardEngine engine=null; @@ -447,9 +461,14 @@ engine=(StandardEngine)container.getParent(); suffix=",host=" + container.getName(); } else if( container instanceof StandardContext ) { + String path = ((StandardContext)container).getPath(); + // add "/" to avoid MalformedObjectName Exception + if (path.equals("")) { + path = "/"; + } engine=(StandardEngine)container.getParent().getParent(); - suffix=",host=" + container.getParent().getName() + - ",path=" + ((StandardContext)container).getPath(); + suffix= ",path=" + path + ",host=" + + container.getParent().getName(); } else { log.error("Unknown container " + container ); } @@ -463,5 +482,89 @@ } return oname; } + + + // ------------------------------------------------------ Lifecycle Methods + /** + * Add a lifecycle event listener to this component. + * + * @param listener The listener to add + */ + public void addLifecycleListener(LifecycleListener listener) { + + lifecycle.addLifecycleListener(listener); + + } + + + /** + * Get the lifecycle listeners associated with this lifecycle. If this + * Lifecycle has no listeners registered, a zero-length array is returned. + */ + public LifecycleListener[] findLifecycleListeners() { + + return lifecycle.findLifecycleListeners(); + + } + + + /** + * Remove a lifecycle event listener from this component. + * + * @param listener The listener to add + */ + public void removeLifecycleListener(LifecycleListener listener) { + + lifecycle.removeLifecycleListener(listener); + + } + + + /** + * Prepare for the beginning of active use of the public methods of this + * component. This method should be called after <code>configure()</code>, + * and before any of the public methods of the component are utilized. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ + public void start() throws LifecycleException { + + // register this logger + if ( getObjectName()==null ) { + ObjectName oname = createObjectName(); + try { + Registry.getRegistry().registerComponent(this, oname, null); + log.info( "registering logger " + oname ); + } catch( Exception ex ) { + log.error( "Can't register logger " + oname, ex); + } + } + + } + + + /** + * Gracefully terminate the active use of the public methods of this + * component. This method should be the last one called on a given + * instance of this component. + * + * @exception LifecycleException if this component detects a fatal error + * that needs to be reported + */ + public void stop() throws LifecycleException { + + // unregister this logger + if ( getObjectName()!=null ) { + ObjectName oname = createObjectName(); + try { + Registry.getRegistry().unregisterComponent(oname); + log.info( "unregistering logger " + oname ); + } catch( Exception ex ) { + log.error( "Can't unregister logger " + oname, ex); + } + } + } + } 1.11 +79 -86 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java Index: MBeanFactory.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- MBeanFactory.java 24 Mar 2003 09:18:26 -0000 1.10 +++ MBeanFactory.java 27 Mar 2003 03:06:39 -0000 1.11 @@ -198,6 +198,30 @@ return t; } + + /** + * Get Parent DefaultContext to add its child component + * from parent's ObjectName + */ + private DefaultContext getDefaultContext(ObjectName pname) + throws Exception { + + String type = pname.getKeyProperty("type"); + if (type.equals("DefaultContext")) { + Service service = getService(pname); + StandardEngine engine = (StandardEngine) service.getContainer(); + String hostName = pname.getKeyProperty("host"); + if (hostName!=null) { + StandardHost host = + (StandardHost) engine.findChild(hostName); + return host.getDefaultContext(); + } else { + return engine.getDefaultContext(); + } + } + return null; + } + /** * Get Parent ContainerBase to add its child component @@ -208,19 +232,7 @@ String type = pname.getKeyProperty("type"); String j2eeType = pname.getKeyProperty("j2eeType"); - String domain = pname.getDomain(); - Server server = ServerFactory.getServer(); - Service[] services = server.findServices(); - StandardService service = null; - for (int i = 0; i < services.length; i++) { - service = (StandardService) services[i]; - if (domain.equals(service.getObjectName().getDomain())) { - break; - } - } - if (!service.getObjectName().getDomain().equals(domain)) { - throw new Exception("Service with the domain is not found"); - } + Service service = getService(pname); StandardEngine engine = (StandardEngine) service.getContainer(); if ((j2eeType!=null) && (j2eeType.equals("WebModule"))) { String name = pname.getKeyProperty("name"); @@ -253,21 +265,9 @@ private ContainerBase getParentContainerFromChild(ObjectName oname) throws Exception { - String domain = oname.getDomain(); String hostName = oname.getKeyProperty("host"); String path = oname.getKeyProperty("path"); - Server server = ServerFactory.getServer(); - Service[] services = server.findServices(); - StandardService service = null; - for (int i = 0; i < services.length; i++) { - service = (StandardService) services[i]; - if (domain.equals(service.getObjectName().getDomain())) { - break; - } - } - if (!service.getObjectName().getDomain().equals(domain)) { - throw new Exception("Service with the domain is not found"); - } + Service service = getService(oname); StandardEngine engine = (StandardEngine) service.getContainer(); if (hostName == null) { // child's container is Engine @@ -322,10 +322,7 @@ ContainerBase containerBase = getParentContainerFromParent(pname); // Add the new instance to its parent component containerBase.addValve(accessLogger); - //FIXME getObjectName() returns null - //ObjectName oname = accessLogger.getObjectName(); - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), accessLogger); + ObjectName oname = accessLogger.getObjectName(); return (oname.toString()); } @@ -409,13 +406,7 @@ // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); - String type = pname.getKeyProperty("type"); - Server server = ServerFactory.getServer(); - String serviceName = pname.getKeyProperty("service"); - if (serviceName == null) { - serviceName = pname.getKeyProperty("name"); - } - Service service = server.findService(serviceName); + Service service = getService(pname); Engine engine = (Engine) service.getContainer(); String hostName = pname.getKeyProperty("host"); if (hostName == null) { //if DefaultContext is nested in Engine @@ -455,10 +446,7 @@ // Add the new instance to its parent component containerBase.setLogger(fileLogger); // Return the corresponding MBean name - //ObjectName oname = fileLogger.getObjectName(); - //FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), fileLogger); + ObjectName oname = fileLogger.getObjectName(); return (oname.toString()); } @@ -628,11 +616,15 @@ // Add the new instance to its parent component containerBase.setRealm(realm); // Return the corresponding MBean name - // ObjectName oname = realm.getObjectName(); + ObjectName oname = realm.getObjectName(); // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), realm); - return (oname.toString()); + //ObjectName oname = + // MBeanUtils.createObjectName(pname.getDomain(), realm); + if (oname != null) { + return (oname.toString()); + } else { + return null; + } } @@ -656,11 +648,16 @@ // Add the new instance to its parent component containerBase.setRealm(realm); // Return the corresponding MBean name - //ObjectName oname = realm.getObjectName(); + ObjectName oname = realm.getObjectName(); // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), realm); - return (oname.toString()); + //ObjectName oname = + // MBeanUtils.createObjectName(pname.getDomain(), realm); + if (oname != null) { + return (oname.toString()); + } else { + return null; + } + } @@ -688,7 +685,11 @@ // FIXME getObjectName() returns null ObjectName oname = MBeanUtils.createObjectName(pname.getDomain(), realm); - return (oname.toString()); + if (oname != null) { + return (oname.toString()); + } else { + return null; + } } @@ -710,10 +711,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.addValve(valve); - //ObjectName oname = valve.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), valve); + ObjectName oname = valve.getObjectName(); return (oname.toString()); } @@ -736,10 +734,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.addValve(valve); - //ObjectName oname = valve.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), valve); + ObjectName oname = valve.getObjectName(); return (oname.toString()); } @@ -762,10 +757,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.addValve(valve); - //ObjectName oname = valve.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), valve); + ObjectName oname = valve.getObjectName(); return (oname.toString()); } @@ -788,10 +780,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.addValve(valve); - //ObjectName oname = valve.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), valve); + ObjectName oname = valve.getObjectName(); return (oname.toString()); } @@ -960,7 +949,9 @@ // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); - containerBase.setManager(manager); + if (containerBase != null) { + containerBase.setManager(manager); + } //ObjectName oname = manager.getObjectName(); // FIXME getObjectName() returns null ObjectName oname = @@ -1013,10 +1004,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.setLogger(logger); - //ObjectName oname = logger.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), logger); + ObjectName oname = logger.getObjectName(); return (oname.toString()); } @@ -1039,10 +1027,7 @@ ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); containerBase.setLogger(logger); - //ObjectName oname = logger.getObjectName(); - // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), logger); + ObjectName oname = logger.getObjectName(); return (oname.toString()); } @@ -1070,11 +1055,16 @@ // Add the new instance to its parent component containerBase.setRealm(realm); // Return the corresponding MBean name - //ObjectName oname = realm.getObjectName(); + ObjectName oname = realm.getObjectName(); // FIXME getObjectName() returns null - ObjectName oname = - MBeanUtils.createObjectName(pname.getDomain(), realm); - return (oname.toString()); + //ObjectName oname = + // MBeanUtils.createObjectName(pname.getDomain(), realm); + if (oname != null) { + return (oname.toString()); + } else { + return null; + } + } @@ -1094,7 +1084,9 @@ // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); ContainerBase containerBase = getParentContainerFromParent(pname); - containerBase.setLoader(loader); + if (containerBase != null) { + containerBase.setLoader(loader); + } // FIXME add Loader.getObjectName //ObjectName oname = loader.getObjectName(); ObjectName oname = @@ -1308,9 +1300,10 @@ ObjectName oname = new ObjectName(name); ContainerBase container = getParentContainerFromChild(oname); String sequence = oname.getKeyProperty("seq"); - ValveBase[] valves = (ValveBase[])container.getValves(); + Valve[] valves = (Valve[])container.getValves(); for (int i = 0; i < valves.length; i++) { - if ((valves[i].getObjectName().toString()).equals(name)) { + ObjectName voname = ((ValveBase) valves[i]).getObjectName(); + if (voname.equals(oname)) { container.removeValve(valves[i]); } } 1.9 +5 -4 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java Index: RealmBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/realm/RealmBase.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- RealmBase.java 20 Mar 2003 15:57:39 -0000 1.8 +++ RealmBase.java 27 Mar 2003 03:06:39 -0000 1.9 @@ -1071,6 +1071,7 @@ ContainerBase cb=(ContainerBase)container; oname=new ObjectName(cb.getDomain()+":type=Realm" + cb.getContainerSuffix()); Registry.getRegistry().registerComponent(this, oname, null ); + log.info("Register Realm "+oname); } catch (Throwable e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. } 1.6 +8 -5 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ValveBase.java Index: ValveBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ValveBase.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ValveBase.java 20 Mar 2003 16:01:33 -0000 1.5 +++ ValveBase.java 27 Mar 2003 03:06:39 -0000 1.6 @@ -323,7 +323,10 @@ ext=",seq=" + seq; } - return new ObjectName( domain + ":type=Valve,name=" + className + ext + parentName); + ObjectName objectName = + new ObjectName( domain + ":type=Valve,name=" + className + ext + parentName); + log.info("valve objectname = "+objectName); + return objectName; } // -------------------- JMX data --------------------
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]