tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amy...@apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans MBeanUtils.java ServerLifecycleListener.java
Date Mon, 14 Jan 2002 21:42:37 GMT
amyroh      02/01/14 13:42:37

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        MBeanUtils.java ServerLifecycleListener.java
  Log:
  Add createMBean, createObjectName, and destroyMBean methods for Loader and Manager.
  
  Revision  Changes    Path
  1.7       +173 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MBeanUtils.java	14 Nov 2001 03:51:06 -0000	1.6
  +++ MBeanUtils.java	14 Jan 2002 21:42:37 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
1.6 2001/11/14 03:51:06 amyroh Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/11/14 03:51:06 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/MBeanUtils.java,v
1.7 2002/01/14 21:42:37 amyroh Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/01/14 21:42:37 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,9 @@
   import org.apache.catalina.Host;
   import org.apache.catalina.LifecycleEvent;
   import org.apache.catalina.LifecycleListener;
  +import org.apache.catalina.Loader;
   import org.apache.catalina.Logger;
  +import org.apache.catalina.Manager;
   import org.apache.catalina.Realm;
   import org.apache.catalina.Server;
   import org.apache.catalina.ServerFactory;
  @@ -102,7 +104,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.6 $ $Date: 2001/11/14 03:51:06 $
  + * @version $Revision: 1.7 $ $Date: 2002/01/14 21:42:37 $
    */
   
   public class MBeanUtils {
  @@ -261,6 +263,29 @@
   
       /**
        * Create, register, and return an MBean for this
  +     * <code>Loader</code> object.
  +     *
  +     * @param loader The Loader to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(Loader loader)
  +        throws Exception {
  +
  +        String mname = createManagedName(loader);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ModelMBean mbean = managed.createMBean(loader);
  +        ObjectName oname = createObjectName(domain, loader);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +
  +    /**
  +     * Create, register, and return an MBean for this
        * <code>Logger</code> object.
        *
        * @param logger The Logger to be managed
  @@ -285,6 +310,29 @@
   
       /**
        * Create, register, and return an MBean for this
  +     * <code>Manager</code> object.
  +     *
  +     * @param manager The Manager to be managed
  +     *
  +     * @exception Exception if an MBean cannot be created or registered
  +     */
  +    public static ModelMBean createMBean(Manager manager)
  +        throws Exception {
  +
  +        String mname = createManagedName(manager);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ModelMBean mbean = managed.createMBean(manager);
  +        ObjectName oname = createObjectName(domain, manager);
  +        mserver.registerMBean(mbean, oname);
  +        return (mbean);
  +
  +    }
  +
  +    /**
  +     * Create, register, and return an MBean for this
        * <code>Realm</code> object.
        *
        * @param realm The Realm to be managed
  @@ -498,6 +546,45 @@
   
       /**
        * Create an <code>ObjectName</code> for this
  +     * <code>Loader</code> object.
  +     *
  +     * @param domain Domain in which this name is to be created
  +     * @param loader The Loader to be named
  +     *
  +     * @exception MalformedObjectNameException if a name cannot be created
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              Loader loader)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        Container container = loader.getContainer();
  +
  +        if (container instanceof Engine) {
  +            Service service = ((Engine)container).getService();
  +            name = new ObjectName(domain + ":type=Loader,service=" +
  +                              service.getName());
  +        } else if (container instanceof Host) {
  +            Service service = ((Engine)container.getParent()).getService();
  +            name = new ObjectName(domain + ":type=Loader,host=" +
  +                              container.getName() + ",service=" +
  +                              service.getName());
  +        } else if (container instanceof Context) {
  +            String path = ((Context)container).getPath();
  +            Host host = (Host) container.getParent();
  +            Service service = ((Engine)container.getParent()).getService();
  +            name = new ObjectName(domain + ":type=Loader,path=" + path +
  +                              ",host=" + host.getName() + ",service=" +
  +                              service.getName());
  +        }
  +
  +        return (name);
  +
  +    }
  +
  +
  +    /**
  +     * Create an <code>ObjectName</code> for this
        * <code>Logger</code> object.
        *
        * @param domain Domain in which this name is to be created
  @@ -537,6 +624,45 @@
   
       /**
        * Create an <code>ObjectName</code> for this
  +     * <code>Manager</code> object.
  +     *
  +     * @param domain Domain in which this name is to be created
  +     * @param manager The Manager to be named
  +     *
  +     * @exception MalformedObjectNameException if a name cannot be created
  +     */
  +    public static ObjectName createObjectName(String domain,
  +                                              Manager manager)
  +        throws MalformedObjectNameException {
  +
  +        ObjectName name = null;
  +        Container container = manager.getContainer();
  +
  +        if (container instanceof Engine) {
  +            Service service = ((Engine)container).getService();
  +            name = new ObjectName(domain + ":type=Manager,service=" +
  +                              service.getName());
  +        } else if (container instanceof Host) {
  +            Service service = ((Engine)container.getParent()).getService();
  +            name = new ObjectName(domain + ":type=Manager,host=" +
  +                              container.getName() + ",service=" +
  +                              service.getName());
  +        } else if (container instanceof Context) {
  +            String path = ((Context)container).getPath();
  +            Host host = (Host) container.getParent();
  +            Service service = ((Engine)container.getParent()).getService();
  +            name = new ObjectName(domain + ":type=Manager,path=" + path +
  +                              ",host=" + host.getName() + ",service=" +
  +                              service.getName());
  +        }
  +
  +        return (name);
  +
  +    }
  +
  +    
  +    /**
  +     * Create an <code>ObjectName</code> for this
        * <code>Realm</code> object.
        *
        * @param domain Domain in which this name is to be created
  @@ -786,6 +912,28 @@
           mserver.unregisterMBean(oname);
   
       }
  +    
  +
  +    /**
  +     * Deregister the MBean for this
  +     * <code>Loader</code> object.
  +     *
  +     * @param loader The Loader to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(Loader loader)
  +        throws Exception {
  +
  +        String mname = createManagedName(loader);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ObjectName oname = createObjectName(domain, loader);
  +        mserver.unregisterMBean(oname);
  +
  +    }
   
   
       /**
  @@ -809,6 +957,27 @@
   
       }
   
  +
  +    /**
  +     * Deregister the MBean for this
  +     * <code>Manager</code> object.
  +     *
  +     * @param manager The Manager to be managed
  +     *
  +     * @exception Exception if an MBean cannot be deregistered
  +     */
  +    public static void destroyMBean(Manager manager)
  +        throws Exception {
  +
  +        String mname = createManagedName(manager);
  +        ManagedBean managed = registry.findManagedBean(mname);
  +        String domain = managed.getDomain();
  +        if (domain == null)
  +            domain = mserver.getDefaultDomain();
  +        ObjectName oname = createObjectName(domain, manager);
  +        mserver.unregisterMBean(oname);
  +
  +    }
   
       /**
        * Deregister the MBean for this
  
  
  
  1.6       +24 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ServerLifecycleListener.java	30 Oct 2001 23:13:55 -0000	1.5
  +++ ServerLifecycleListener.java	14 Jan 2002 21:42:37 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v
1.5 2001/10/30 23:13:55 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2001/10/30 23:13:55 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/ServerLifecycleListener.java,v
1.6 2002/01/14 21:42:37 amyroh Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/01/14 21:42:37 $
    *
    * ====================================================================
    *
  @@ -81,6 +81,9 @@
   import org.apache.catalina.Engine;
   import org.apache.catalina.Globals;
   import org.apache.catalina.Host;
  +import org.apache.catalina.Loader;
  +import org.apache.catalina.Logger;
  +import org.apache.catalina.Manager;
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleEvent;
   import org.apache.catalina.LifecycleListener;
  @@ -97,7 +100,7 @@
    *
    * @author Craig R. McClanahan
    * @author Amy Roh
  - * @version $Revision: 1.5 $ $Date: 2001/10/30 23:13:55 $
  + * @version $Revision: 1.6 $ $Date: 2002/01/14 21:42:37 $
    */
   
   public class ServerLifecycleListener
  @@ -322,6 +325,23 @@
                                   (Globals.MBEAN_SERVER_ATTR, 
                                    MBeanUtils.createServer());
                           }
  +                        Loader loader = context.getLoader();
  +                        if (loader != null) {
  +                            if (debug >= 5)
  +                                log("Creating MBean for Loader " + loader);
  +                            MBeanUtils.createMBean(loader);
  +                            // FIX ME
  +                            //loader.addLifecycleListener(this);
  +                        }
  +                        Manager manager = context.getManager();
  +                        if (manager != null) {
  +                            if (debug >= 5)
  +                                log("Creating MBean for Manager" + manager);
  +                            MBeanUtils.createMBean(manager);
  +                            // FIX ME
  +                            //manager.addLifecycleListener(this);
  +                        }
  +
                       }
   
                   }
  
  
  

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


Mime
View raw message