tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans GlobalResourcesLifecycleListener.java
Date Fri, 31 Jan 2003 21:06:21 GMT
costin      2003/01/31 13:06:21

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        GlobalResourcesLifecycleListener.java
  Log:
  Use commons-logging.
  
  Handle some errors.
  
  Revision  Changes    Path
  1.3       +41 -63    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java
  
  Index: GlobalResourcesLifecycleListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/GlobalResourcesLifecycleListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GlobalResourcesLifecycleListener.java	10 Jan 2003 18:57:06 -0000	1.2
  +++ GlobalResourcesLifecycleListener.java	31 Jan 2003 21:06:21 -0000	1.3
  @@ -65,25 +65,22 @@
   
   
   import java.util.Iterator;
  -import javax.management.MBeanException;
  -import javax.management.MBeanServer;
  -import javax.management.ObjectName;
   import javax.naming.Binding;
   import javax.naming.Context;
   import javax.naming.InitialContext;
   import javax.naming.NamingEnumeration;
   import javax.naming.NamingException;
  +import javax.naming.OperationNotSupportedException;
   import org.apache.catalina.Group;
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleEvent;
   import org.apache.catalina.LifecycleListener;
   import org.apache.catalina.Role;
  -import org.apache.catalina.Server;
   import org.apache.catalina.User;
   import org.apache.catalina.UserDatabase;
  -import org.apache.catalina.core.StandardServer;
  -import org.apache.commons.modeler.ManagedBean;
   import org.apache.commons.modeler.Registry;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   
   /**
  @@ -98,7 +95,7 @@
   
   public class GlobalResourcesLifecycleListener
       implements LifecycleListener {
  -
  +    private static Log log = LogFactory.getLog(GlobalResourcesLifecycleListener.class);
   
       // ----------------------------------------------------- Instance Variables
   
  @@ -166,7 +163,7 @@
           try {
               context = (Context) (new InitialContext()).lookup("java:/");
           } catch (NamingException e) {
  -            log("No global naming context defined for server");
  +            log.error("No global naming context defined for server");
               return;
           }
   
  @@ -174,7 +171,7 @@
           try {
               createMBeans("", context);
           } catch (NamingException e) {
  -            log("Exception processing Global JNDI Resources", e);
  +            log.error("Exception processing Global JNDI Resources", e);
           }
   
       }
  @@ -193,28 +190,34 @@
           throws NamingException {
   
           if (debug >= 1) {
  -            log("Creating MBeans for Global JNDI Resources in Context '" +
  +            log.debug("Creating MBeans for Global JNDI Resources in Context '" +
                   prefix + "'");
           }
   
  -        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) {
  -                try {
  -                    createMBeans(name, (UserDatabase) value);
  -                } catch (Exception e) {
  -                    log("Exception creating UserDatabase MBeans for " + name,
  -                        e);
  +        try {
  +            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.debug("Checking resource " + name);
  +                }
  +                if (value instanceof Context) {
  +                    createMBeans(name + "/", (Context) value);
  +                } else if (value instanceof UserDatabase) {
  +                    try {
  +                        createMBeans(name, (UserDatabase) value);
  +                    } catch (Exception e) {
  +                        log.error("Exception creating UserDatabase MBeans for " + name,
  +                                e);
  +                    }
                   }
               }
  +        } catch( RuntimeException ex) {
  +            log.error("RuntimeException " + ex);
  +        } catch( OperationNotSupportedException ex) {
  +            log.error("Operation not supported " + ex);
           }
   
       }
  @@ -233,8 +236,8 @@
   
           // Create the MBean for the UserDatabase itself
           if (debug >= 2) {
  -            log("Creating UserDatabase MBeans for resource " + name);
  -            log("Database=" + database);
  +            log.debug("Creating UserDatabase MBeans for resource " + name);
  +            log.debug("Database=" + database);
           }
           if (MBeanUtils.createMBean(database) == null) {
               throw new IllegalArgumentException
  @@ -246,7 +249,7 @@
           while (roles.hasNext()) {
               Role role = (Role) roles.next();
               if (debug >= 3) {
  -                log("  Creating Role MBean for role " + role);
  +                log.error("  Creating Role MBean for role " + role);
               }
               if (MBeanUtils.createMBean(role) == null) {
                   throw new IllegalArgumentException
  @@ -259,7 +262,7 @@
           while (groups.hasNext()) {
               Group group = (Group) groups.next();
               if (debug >= 3) {
  -                log("  Creating Group MBean for group " + group);
  +                log.debug("  Creating Group MBean for group " + group);
               }
               if (MBeanUtils.createMBean(group) == null) {
                   throw new IllegalArgumentException
  @@ -272,7 +275,7 @@
           while (users.hasNext()) {
               User user = (User) users.next();
               if (debug >= 3) {
  -                log("  Creating User MBean for user " + user);
  +                log.debug("  Creating User MBean for user " + user);
               }
               if (MBeanUtils.createMBean(user) == null) {
                   throw new IllegalArgumentException
  @@ -289,40 +292,18 @@
       protected void destroyMBeans() {
   
           if (debug >= 1) {
  -            log("Destroying MBeans for Global JNDI Resources");
  +            log.debug("Destroying MBeans for Global JNDI Resources");
           }
   
       }
   
  -
  -
  -    /**
  -     * The destination for log messages.
  -     */
  -    protected java.io.PrintStream  stream = System.out;
  -
  -
       /**
        * Log a message.
        *
        * @param message The message to be logged
        */
       protected void log(String message) {
  -
  -        /*
  -        if (stream == System.out) {
  -            try {
  -                stream = new java.io.PrintStream
  -                             (new java.io.FileOutputStream("grll.log"));
  -            } catch (Throwable t) {
  -                ;
  -            }
  -        }
  -        */
  -
  -        stream.print("GlobalResourcesLifecycleListener: ");
  -        stream.println(message);
  -
  +        log.info(message);
       }
   
   
  @@ -333,10 +314,7 @@
        * @param throwable The exception to be logged
        */
       protected void log(String message, Throwable throwable) {
  -
  -        log(message);
  -        throwable.printStackTrace(stream);
  -
  +        log.info(message, throwable);
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message