You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2002/06/09 02:23:27 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java ServerLifecycleListener.java

remm        2002/06/08 17:23:27

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        MBeanUtils.java ServerLifecycleListener.java
  Log:
  - Add the possibility to specify external resources where the MBeans definitions
    are. This can be used to declare custom components and keep the admin
    webapp happy.
  
  Revision  Changes    Path
  1.39      +26 -4     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.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- MBeanUtils.java	6 Jun 2002 22:36:47 -0000	1.38
  +++ MBeanUtils.java	9 Jun 2002 00:23:27 -0000	1.39
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v 1.38 2002/06/06 22:36:47 amyroh Exp $
  - * $Revision: 1.38 $
  - * $Date: 2002/06/06 22:36:47 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v 1.39 2002/06/09 00:23:27 remm Exp $
  + * $Revision: 1.39 $
  + * $Date: 2002/06/09 00:23:27 $
    *
    * ====================================================================
    *
  @@ -116,7 +116,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.38 $ $Date: 2002/06/06 22:36:47 $
  + * @version $Revision: 1.39 $ $Date: 2002/06/09 00:23:27 $
    */
   
   public class MBeanUtils {
  @@ -1461,6 +1461,28 @@
               }
           }
           return (registry);
  +
  +    }
  +
  +
  +    /**
  +     * Load an MBean descriptor resource.
  +     */
  +    public synchronized static void loadMBeanDescriptors(String resource) {
  +
  +        try {
  +            URL url = ServerLifecycleListener.class.getResource(resource);
  +            if (url != null) {
  +                InputStream stream = url.openStream();
  +                Registry.loadRegistry(stream);
  +                stream.close();
  +            } else {
  +                // XXX: i18n
  +                System.out.println("MBean descriptors not found:" + resource);
  +            }
  +        } catch (Throwable t) {
  +            t.printStackTrace(System.out);
  +        }
   
       }
   
  
  
  
  1.26      +48 -4     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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ServerLifecycleListener.java	3 May 2002 23:45:40 -0000	1.25
  +++ ServerLifecycleListener.java	9 Jun 2002 00:23:27 -0000	1.26
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v 1.25 2002/05/03 23:45:40 amyroh Exp $
  - * $Revision: 1.25 $
  - * $Date: 2002/05/03 23:45:40 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v 1.26 2002/06/09 00:23:27 remm Exp $
  + * $Revision: 1.26 $
  + * $Date: 2002/06/09 00:23:27 $
    *
    * ====================================================================
    *
  @@ -66,10 +66,12 @@
   
   import java.beans.PropertyChangeEvent;
   import java.beans.PropertyChangeListener;
  +import java.io.File;
   import java.io.InputStream;
   import java.net.URL;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.StringTokenizer;
   import javax.management.MBeanException;
   import javax.management.MBeanServer;
   import javax.management.ObjectName;
  @@ -111,7 +113,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.25 $ $Date: 2002/05/03 23:45:40 $
  + * @version $Revision: 1.26 $ $Date: 2002/06/09 00:23:27 $
    */
   
   public class ServerLifecycleListener
  @@ -135,6 +137,20 @@
       }
   
   
  +    /**
  +     * Semicolon separated list of paths containing MBean desciptor resources.
  +     */
  +    protected String descriptors = null;
  +
  +    public String getDescriptors() {
  +        return (this.descriptors);
  +    }
  +
  +    public void setDescriptors(String descriptors) {
  +        this.descriptors = descriptors;
  +    }
  +
  +
       // ---------------------------------------------- ContainerListener Methods
   
   
  @@ -180,9 +196,16 @@
   
           Lifecycle lifecycle = event.getLifecycle();
           if (Lifecycle.START_EVENT.equals(event.getType())) {
  +
               if (lifecycle instanceof Server) {
  +
  +                // Loading additional MBean descriptors
  +                loadMBeanDescriptors();
  +
                   createMBeans();
  +
               }
  +
               /*
               // Ignore events from StandardContext objects to avoid
               // reregistering the context
  @@ -190,11 +213,15 @@
                   return;
               createMBeans();
               */
  +
           } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
  +
               if (lifecycle instanceof Server) {
                   destroyMBeans();
               }
  +
           } else if (Context.RELOAD_EVENT.equals(event.getType())) {
  +
               // Give context a new handle to the MBean server if the
               // context has been reloaded since reloading causes the
               // context to lose its previous handle to the server
  @@ -211,6 +238,7 @@
                            MBeanUtils.createServer());
                   }
               }
  +
           }
   
       }
  @@ -270,6 +298,22 @@
   
   
       // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Load additional MBean descriptor resources.
  +     */
  +    protected void loadMBeanDescriptors() {
  +
  +        if (descriptors != null) {
  +            StringTokenizer tokenizer = new StringTokenizer(descriptors, ";");
  +            while (tokenizer.hasMoreTokens()) {
  +                String resource = tokenizer.nextToken();
  +                MBeanUtils.loadMBeanDescriptors(resource);
  +            }
  +        }
  +
  +    }
   
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>