costin 2003/01/30 12:46:51 Modified: catalina/src/share/org/apache/catalina/mbeans GlobalResourcesLifecycleListener.java ServerLifecycleListener.java Log: Few fixes to make the listeners more friendly to foreign environments. The ServerLifecycle will be useable if it is added to a Service ( as is the case when tomcat is embeded ). The Global listener will work with othe JNDI implementations. Revision Changes Path 1.4 +43 -21 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java Index: GlobalResourcesLifecycleListener.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GlobalResourcesLifecycleListener.java 3 Feb 2002 00:56:57 -0000 1.3 +++ GlobalResourcesLifecycleListener.java 30 Jan 2003 20:46:50 -0000 1.4 @@ -69,8 +69,10 @@ import javax.management.MBeanServer; import javax.management.ObjectName; import javax.naming.Binding; +import javax.naming.CompositeName; import javax.naming.Context; import javax.naming.InitialContext; +import javax.naming.OperationNotSupportedException; import javax.naming.NamingEnumeration; import javax.naming.NamingException; import org.apache.catalina.Group; @@ -162,20 +164,26 @@ protected void createMBeans() { // Look up our global naming context - Context context = null; + Object context = null; try { - context = (Context) (new InitialContext()).lookup("java:/"); + context = (new InitialContext()).lookup("java:/"); } catch (NamingException e) { e.printStackTrace(); throw new IllegalStateException ("No global naming context defined for server"); } + log( "Global context " + context + " " + context.getClass().getName()); + if( ! (context instanceof Context) ) + return; + // Recurse through the defined global JNDI resources context try { - createMBeans("", context); + createMBeans("", (Context)context); } catch (NamingException e) { log("Exception processing Global JNDI Resources", e); + } catch (RuntimeException e) { + log("RuntimeException processing Global JNDI Resources" + e.toString()); } } @@ -195,26 +203,40 @@ if (debug >= 1) { log("Creating MBeans for Global JNDI Resources in Context '" + - prefix + "'"); + prefix + "' " + context ); } NamingEnumeration bindings = context.listBindings(""); while (bindings.hasMore()) { - Binding binding = (Binding) bindings.next(); - String name = prefix + binding.getName(); - Object value = context.lookup(binding.getName()); - if (debug >= 2) { - log("Checking resource " + name); - } - if (value instanceof Context) { - createMBeans(name + "/", (Context) value); - } else if (value instanceof UserDatabase) { + Object next=bindings.next(); + if( next instanceof Binding ) { + Binding binding = (Binding) bindings.next(); + String name = prefix + binding.getName(); + Object value = context.lookup(binding.getName()); + if (debug >= 1 && name!=null) { + log("Processing resource " + name + " " + name.getClass().getName()); + } try { - createMBeans(name, (UserDatabase) value); - } catch (Exception e) { - log("Exception creating UserDatabase MBeans for " + name, - e); + if (value instanceof Context) { + createMBeans(name + "/", (Context) value); + } else if (value instanceof UserDatabase) { + try { + createMBeans(name, (UserDatabase) value); + } catch (Exception e) { + log("Exception creating UserDatabase MBeans for " + name, + e); + } + } + } catch( OperationNotSupportedException nex ) { + log( "OperationNotSupportedException processing " + next + " " + nex.toString()); + } catch( NamingException nex ) { + log( "Naming exception processing " + next + " " + nex.toString()); + } catch( RuntimeException ex ) { + log( "Runtime exception processing " + next + " " + ex.toString()); } + } else { + log("Foreign context " + context.getClass().getName() + " " + + next.getClass().getName()+ " " + context); } } 1.36 +32 -8 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.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- ServerLifecycleListener.java 20 Sep 2002 21:20:44 -0000 1.35 +++ ServerLifecycleListener.java 30 Jan 2003 20:46:51 -0000 1.36 @@ -206,7 +206,19 @@ createMBeans(); } - + + // We are embedded. + if( lifecycle instanceof Service ) { + log( "Starting embeded" + lifecycle); + try { + MBeanFactory factory = new MBeanFactory(); + createMBeans(factory); + loadMBeanDescriptors(); + createMBeans((Service)lifecycle); + } catch( Exception ex ) { + log("Error registering the service", ex); + } + } /* // Ignore events from StandardContext objects to avoid // reregistering the context @@ -565,13 +577,21 @@ if (eLogger != null) { if (debug >= 2) log("Creating MBean for Logger " + eLogger); - MBeanUtils.createMBean(eLogger); + try { + MBeanUtils.createMBean(eLogger); + } catch( Exception ex ) { + log( "Can't create mbean for logger " + eLogger ); + } } Realm eRealm = engine.getRealm(); if (eRealm != null) { if (debug >= 2) log("Creating MBean for Realm " + eRealm); - MBeanUtils.createMBean(eRealm); + try { + MBeanUtils.createMBean(eRealm); + } catch( Exception ex ) { + log( "Can't create mbean for realm " + eRealm ); + } } // Create the MBeans for the associated Valves @@ -580,7 +600,11 @@ for (int j = 0; j < eValves.length; j++) { if (debug >= 2) log("Creating MBean for Valve " + eValves[j]); - MBeanUtils.createMBean(eValves[j]); + try { + MBeanUtils.createMBean(eValves[j]); + } catch( Exception ex ) { + log( "Can't create mbean for valve " + eRealm ); + } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]