tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From billbar...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans MBeanFactory.java
Date Wed, 04 Aug 2004 06:51:13 GMT
billbarker    2004/08/03 23:51:13

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        MBeanFactory.java
  Log:
  Update the admin webapp to use the new Deployer.
  
  Revision  Changes    Path
  1.28      +65 -13    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java
  
  Index: MBeanFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/mbeans/MBeanFactory.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- MBeanFactory.java	30 Jul 2004 03:01:34 -0000	1.27
  +++ MBeanFactory.java	4 Aug 2004 06:51:13 -0000	1.28
  @@ -19,6 +19,7 @@
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
   import java.util.Vector;
  +import java.io.File;
   
   import javax.management.MBeanException;
   import javax.management.MBeanServer;
  @@ -70,6 +71,9 @@
   
   public class MBeanFactory extends BaseModelMBean {
   
  +    private static org.apache.commons.logging.Log log = 
  +        org.apache.commons.logging.LogFactory.getLog(MBeanFactory.class);
  +
       /**
        * The <code>MBeanServer</code> for this application.
        */
  @@ -632,6 +636,19 @@
               createStandardContext(parent,path,docBase,false,false,false,false);       
                          
       }
   
  +    /**
  +     * Given a context path, get the config file name.
  +     */
  +    private String getConfigFile(String path) {
  +        String basename = null;
  +        if (path.equals("")) {
  +            basename = "ROOT";
  +        } else {
  +            basename = path.substring(1).replace('/', '#');
  +        }
  +        return (basename);
  +    }
  +
      /**
        * Create a new StandardContext.
        *
  @@ -665,14 +682,36 @@
   
           // Add the new instance to its parent component
           ObjectName pname = new ObjectName(parent);
  -        Service service = getService(pname);
  -        Engine engine = (Engine) service.getContainer();
  -        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
  -        host.addChild(context);
  +        ObjectName deployer = new ObjectName(pname.getDomain()+
  +                                             ":type=Deployer,host="+
  +                                             pname.getKeyProperty("host"));
  +        if(mserver.isRegistered(deployer)) {
  +            String contextPath = context.getPath();
  +            mserver.invoke(deployer, "addServiced",
  +                           new Object [] {contextPath},
  +                           new String [] {"java.lang.String"});
  +            String configPath = (String)mserver.getAttribute(deployer,
  +                                                             "configBaseName");
  +            String baseName = getConfigFile(contextPath);
  +            File configFile = new File(new File(configPath), baseName+".xml");
  +            context.setConfigFile(configFile.getAbsolutePath());
  +            mserver.invoke(deployer, "manageApp",
  +                           new Object[] {context},
  +                           new String[] {"org.apache.catalina.Context"});
  +            mserver.invoke(deployer, "removeServiced",
  +                           new Object [] {contextPath},
  +                           new String [] {"java.lang.String"});
  +        } else {
  +            log.warn("Deployer not found for "+pname.getKeyProperty("host"));
  +            Service service = getService(pname);
  +            Engine engine = (Engine) service.getContainer();
  +            Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
  +            host.addChild(context);
  +        }
   
           // Return the corresponding MBean name
           ObjectName oname = context.getJmxName();
  -    //            MBeanUtils.createObjectName(pname.getDomain(), context);
  +
           return (oname.toString());
   
       }
  @@ -942,20 +981,33 @@
           ObjectName oname = new ObjectName(contextName);
           String domain = oname.getDomain();
           StandardService service = (StandardService) getService(oname);
  -        if (!service.getObjectName().getDomain().equals(domain)) {
  -            throw new Exception("Service with the domain is not found");
  -        }        
  +
           Engine engine = (Engine) service.getContainer();
           String name = oname.getKeyProperty("name");
           name = name.substring(2);
           int i = name.indexOf("/");
           String hostName = name.substring(0,i);
           String path = name.substring(i);
  -        Host host = (Host) engine.findChild(hostName);
  +        ObjectName deployer = new ObjectName(domain+":type=Deployer,host="+
  +                                             hostName);
           String pathStr = getPathStr(path);
  -        Context context = (Context) host.findChild(pathStr);
  -        // Remove this component from its parent component
  -        host.removeChild(context);
  +        if(mserver.isRegistered(deployer)) {
  +            mserver.invoke(deployer,"addServiced",
  +                           new Object[]{pathStr},
  +                           new String[] {"java.lang.String"});
  +            mserver.invoke(deployer,"unmanageApp",
  +                           new Object[] {pathStr},
  +                           new String[] {"java.lang.String"});
  +            mserver.invoke(deployer,"removeServiced",
  +                           new Object[] {pathStr},
  +                           new String[] {"java.lang.String"});
  +        } else {
  +            log.warn("Deployer not found for "+hostName);
  +            Host host = (Host) engine.findChild(hostName);
  +            Context context = (Context) host.findChild(pathStr);
  +            // Remove this component from its parent component
  +            host.removeChild(context);
  +        }
   
       }
   
  
  
  

---------------------------------------------------------------------
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