costin 2003/03/20 07:55:29 Modified: catalina/src/share/org/apache/catalina/core ContainerBase.java Log: Fix valve registration. Few methods to simplify registration. You'll see a lot of valves ( about 130 with the default webapps ). We could filter out "trivial" valves - but I would rather leave them in as an incentive to eliminate some ( and reduce the stack trace size, memory use, etc :-) For each servlet we have a pipeline with a single valve - the standard wrapper valve. It should be possible to configure per-servlet valves ( not sure how to do it with server.xml, but with jmx it's not hard ) - but that doesn't mean we need all this indirections. Revision Changes Path 1.11 +66 -15 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ContainerBase.java 19 Mar 2003 07:32:48 -0000 1.10 +++ ContainerBase.java 20 Mar 2003 15:55:28 -0000 1.11 @@ -159,7 +159,6 @@ * class comments of the implementation class. * * @author Craig R. McClanahan - * @version $Revision$ $Date$ */ public abstract class ContainerBase @@ -1210,6 +1209,24 @@ } } } + // If we are registered and the valve is not - create a default name + Valve valves[]=getValves(); + for( int i=0; i<valves.length; i++ ) { + Valve valve=valves[i]; + //log.info("Valve: " + this + " " + valve + " " + domain ); + if( valve instanceof ValveBase && + ((ValveBase)valve).getObjectName()==null ) { + 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); + } catch( Throwable t ) { + log.info( "Can't register valve " + valve , t ); + } + } + } // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); @@ -1348,20 +1365,13 @@ public synchronized void addValve(Valve valve) { pipeline.addValve(valve); - // If we are registered and the valve is not - create a default name - if( domain != null && valve instanceof ValveBase && - ((ValveBase)valve).getObjectName()==null ) { - try { - ObjectName vname=((ValveBase)valve).createObjectName(domain, this.getObjectName()); - Registry.getRegistry().registerComponent(valve, vname, valve.getClass().getName()); - ((ValveBase)valve).setController(oname); - } catch( Throwable t ) { - log.info( "Can't register valve " + valve , t ); - } - } fireContainerEvent(ADD_VALVE_EVENT, valve); } + public ObjectName[] getValveNames() { + return ((StandardPipeline)pipeline).getValveNames(); + } + /** * <p>Return the Valve instance that has been distinguished as the basic * Valve for this Pipeline (if any). @@ -1394,13 +1404,12 @@ public synchronized void removeValve(Valve valve) { pipeline.removeValve(valve); - if( domain != null && - valve instanceof ValveBase ) { + if( valve instanceof ValveBase ) { try { ValveBase vb=(ValveBase)valve; if( vb.getController()!=null && vb.getController() == oname ) { - + ObjectName vname=vb.getObjectName(); Registry.getRegistry().getMBeanServer().unregisterMBean(vname); } @@ -1546,6 +1555,16 @@ } public String getDomain() { + if( domain==null ) { + Container parent=this; + while( parent != null && + !( parent instanceof StandardEngine) ) { + parent=parent.getParent(); + } + if( parent instanceof StandardEngine ) { + domain=((StandardEngine)parent).getName(); + } + } return domain; } @@ -1610,5 +1629,37 @@ return null; } + public String getContainerSuffix() { + Container container=this; + Container context=null; + Container host=null; + Container servlet=null; + + StringBuffer suffix=new StringBuffer(); + + if( container instanceof StandardHost ) { + host=container; + } else if( container instanceof StandardContext ) { + host=container.getParent(); + context=container; + } else if( container instanceof StandardWrapper ) { + context=container.getParent(); + 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); + } + if( servlet != null ) { + String name=container.getName(); + suffix.append(",servlet="); + suffix.append((name=="") ? "/" : name); + } + return suffix.toString(); + } + + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]