geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/jmx JMXKernel.java
Date Sat, 16 Aug 2003 19:03:09 GMT
jboynes     2003/08/16 12:03:09

  Modified:    modules/core/src/java/org/apache/geronimo Main.java
               modules/core/src/java/org/apache/geronimo/deployment
                        DeploymentController.java
               modules/core/src/java/org/apache/geronimo/deployment/service
                        ServiceDeploymentPlannerMBean.java
  Added:       modules/core/src/conf client.mlet
               modules/core/src/java/org/apache/geronimo/client
                        AppClient.java AppClientMBean.java
                        ClientDeploymentPlanner.java
                        ClientDeploymentPlannerMBean.java Launcher.java
               modules/core/src/java/org/apache/geronimo/deployment
                        DeploymentPlanner.java
               modules/core/src/java/org/apache/geronimo/jmx JMXKernel.java
  Log:
  Initial cut of ApplicationClient launcher
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/core/src/conf/client.mlet
  
  Index: client.mlet
  ===================================================================
  <MLET CODE="javax.management.relation.RelationService"
        NAME="geronimo.boot:role=RelationService"
        ARCHIVE=""
        >
        <ARG type="boolean" value="true" />
  </MLET>
  
  <MLET CODE="org.apache.geronimo.deployment.DeploymentController"
        NAME="geronimo.deployment:role=DeploymentController"
        ARCHIVE=""
        >
  </MLET>
  
  <MLET CODE="org.apache.geronimo.client.ClientDeploymentPlanner"
        NAME="geronimo.deployment:role=DeploymentPlanner,type=Client"
        ARCHIVE=""
        >
  </MLET>
  
  
  
  
  1.7       +36 -60    incubator-geronimo/modules/core/src/java/org/apache/geronimo/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/Main.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Main.java	14 Aug 2003 17:23:38 -0000	1.6
  +++ Main.java	16 Aug 2003 19:03:08 -0000	1.7
  @@ -59,17 +59,15 @@
   import java.net.URL;
   import java.util.Iterator;
   import java.util.Set;
  -
   import javax.management.MBeanServer;
  -import javax.management.MBeanServerFactory;
   import javax.management.ObjectInstance;
   import javax.management.ObjectName;
  -import javax.management.loading.MLet;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.impl.LogFactoryImpl;
   import org.apache.geronimo.deployment.DeploymentException;
  +import org.apache.geronimo.jmx.JMXKernel;
   
   /**
    *
  @@ -80,10 +78,11 @@
   public class Main implements Runnable {
       static {
           // Add our default Commons Logger that support the trace level
  -        if(System.getProperty(LogFactoryImpl.LOG_PROPERTY) == null) {
  +        if (System.getProperty(LogFactoryImpl.LOG_PROPERTY) == null) {
               System.setProperty(LogFactoryImpl.LOG_PROPERTY, "org.apache.geronimo.core.log.Log4jLog");
           }
       }
  +
       private static final Log log = LogFactory.getLog("Geronimo");
       private static final String[] DEPLOY_ARG_TYPES = {"java.net.URL"};
   
  @@ -91,10 +90,7 @@
       private final URL mletURL;
       private final URL bootURL;
   
  -    private MBeanServer mbServer;
  -    private ObjectName serverName;
  -    private ObjectName bootMLetName;
  -    private Set bootedMBeans;
  +    private ObjectName controllerName;
   
       public Main(String domainName, URL mletURL, URL bootURL) {
           this.domainName = domainName;
  @@ -107,41 +103,48 @@
        */
       public void run() {
           Object[] deployArgs = {bootURL};
  +        JMXKernel kernel = null;
           ShutdownThread hook = new ShutdownThread("Shutdown-Thread", Thread.currentThread());
           try {
               Runtime.getRuntime().addShutdownHook(hook);
               try {
                   long start = System.currentTimeMillis();
   
  -                log.info("Starting MBeanServer");
  -                mbServer = MBeanServerFactory.createMBeanServer(domainName);
  +                log.info("Starting JMXKernel");
  +                kernel = new JMXKernel(domainName);
   
  -                String urlString = mletURL.toString();
  -                log.info("Booting MLets from URL " + urlString);
  +                // boot my kernel MLet
  +                Set bootedMBeans = kernel.bootMLet(mletURL);
   
  -                MLet bootMLet = new MLet();
  -                bootMLetName = mbServer.registerMBean(bootMLet, new ObjectName("geronimo.boot:type=BootMLet,bootURL="
+ ObjectName.quote(urlString))).getObjectName();
  -                bootedMBeans = bootMLet.getMBeansFromURL(mletURL);
  -
  -                // check they all loaded OK
  -                ObjectName serverPattern = new ObjectName("*:role=DeploymentController,*");
  +                // check they all started OK and it included a controller and service planner
  +                ObjectName controllerPattern = new ObjectName("*:role=DeploymentController,*");
  +                ObjectName plannerPattern = new ObjectName("*:role=DeploymentPlanner,type=Service,*");
  +                boolean planner = false;
                   for (Iterator i = bootedMBeans.iterator(); i.hasNext();) {
                       Object o = i.next();
                       if (o instanceof Throwable) {
                           throw (Throwable) o;
                       }
                       ObjectName mletName = ((ObjectInstance) o).getObjectName();
  -                    if (serverPattern.apply(mletName)) {
  -                        if (serverName != null) {
  +                    if (controllerPattern.apply(mletName)) {
  +                        if (controllerName != null) {
                               throw new DeploymentException("Multiple DeploymentControllers
specified in boot mlet");
                           }
  -                        serverName = mletName;
  +                        controllerName = mletName;
  +                    } else if (plannerPattern.apply(mletName)) {
  +                        planner = true;
                       }
                   }
  +                if (controllerName == null) {
  +                    throw new DeploymentException("Boot mlet did not load a DeploymentController");
  +                } else if (!planner) {
  +                    throw new DeploymentException("Boot mlet did not load a DeploymentPlanner
for type=Service");
  +                }
   
                   // start her up
                   log.info("Deploying Bootstrap Services from " + bootURL);
  -                mbServer.invoke(serverName, "deploy", deployArgs, DEPLOY_ARG_TYPES);
  +                MBeanServer mbServer = kernel.getMBeanServer();
  +                mbServer.invoke(controllerName, "deploy", deployArgs, DEPLOY_ARG_TYPES);
   
                   long end = System.currentTimeMillis();
                   log.info("Started Server in " + (end - start) + "ms.");
  @@ -167,48 +170,21 @@
               } catch (Exception e) {
                   // we were in the process of shutting down - ignore
               }
  -            if (serverName != null) {
  -                try {
  -                    log.info("Undeploy Bootstrap Services");
  -                    mbServer.invoke(serverName, "undeploy", deployArgs, DEPLOY_ARG_TYPES);
  -                } catch (Throwable e) {
  -                    log.error("Error stopping Server", e);
  -                }
  -            }
  -
  -            if (bootedMBeans != null) {
  -                for (Iterator i = bootedMBeans.iterator(); i.hasNext();) {
  -                    Object o = i.next();
  -                    if (o instanceof ObjectInstance) {
  -                        ObjectInstance inst = (ObjectInstance) o;
  -                        ObjectName name = inst.getObjectName();
  -                        try {
  -                            log.debug("Unregistering " + name);
  -                            mbServer.unregisterMBean(name);
  -                        } catch (Throwable t) {
  -                            log.error("Error unregistering " + name);
  -                        }
  +            if (kernel != null) {
  +                if (controllerName != null) {
  +                    try {
  +                        log.info("Undeploy Bootstrap Services");
  +                        MBeanServer mbServer = kernel.getMBeanServer();
  +                        mbServer.invoke(controllerName, "undeploy", deployArgs, DEPLOY_ARG_TYPES);
  +                    } catch (Throwable e) {
  +                        log.error("Error stopping Server", e);
                       }
                   }
  -            }
   
  -            if (bootMLetName != null) {
  -                try {
  -                    log.info("Unregistering MLet " + bootMLetName);
  -                    mbServer.unregisterMBean(bootMLetName);
  -                } catch (Throwable t) {
  -                    log.error("Error unregistering MLet ", t);
  -                }
  +                log.info("Releasing JMXKernel");
  +                kernel.release();
               }
   
  -            if (mbServer != null) {
  -                try {
  -                    log.info("Releasing MBeanServer");
  -                    MBeanServerFactory.releaseMBeanServer(mbServer);
  -                } catch (Throwable t) {
  -                    log.error("Error releasing MBeanServer", t);
  -                }
  -            }
               log.info("Shutdown complete");
           }
       }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClient.java
  
  Index: AppClient.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.client;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.net.JarURLConnection;
  import java.net.URL;
  import java.net.URLClassLoader;
  import java.util.jar.Attributes;
  import java.util.jar.Manifest;
  
  import org.apache.geronimo.deployment.DeploymentException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public class AppClient implements AppClientMBean {
      private static final Class[] MAIN_ARGS = {String[].class};
  
      private final ClassLoader clientCL;
  
      private Method mainMethod;
  
      public AppClient(URL clientURL) throws DeploymentException {
          clientCL = new URLClassLoader(new URL[]{clientURL}, Thread.currentThread().getContextClassLoader());
  
          String mainClassName = null;
          try {
              mainClassName = getMainClass(clientURL);
              if (mainClassName == null) {
                  throw new DeploymentException("No Main-Class defined in manifest for " +
clientURL);
              }
          } catch (IOException e) {
              throw new DeploymentException("Unable to get Main-Class from manifest for "
+ clientURL, e);
          }
  
          try {
              Class mainClass = clientCL.loadClass(mainClassName);
              mainMethod = mainClass.getMethod("main", MAIN_ARGS);
          } catch (ClassNotFoundException e) {
              IllegalArgumentException ex = new IllegalArgumentException("Unable to load Main-Class
" + mainClassName);
              ex.initCause(e);
              throw ex;
          } catch (NoSuchMethodException e) {
              IllegalArgumentException ex = new IllegalArgumentException("Main-Class " + mainClassName
+ " does not have a main method");
              ex.initCause(e);
              throw ex;
          }
      }
  
      private String getMainClass(URL url) throws IOException {
          Manifest manifest;
          if (url.toString().endsWith("/")) {
              // unpacked
              URL manifestURL = new URL(url, "META-INF/MANIFEST.MF");
              InputStream is = manifestURL.openStream();
              manifest = new Manifest(is);
              is.close();
          } else {
              URL jarURL = new URL("jar:" + url + "!/");
              JarURLConnection jarConn = (JarURLConnection) jarURL.openConnection();
              manifest = jarConn.getManifest();
          }
          Attributes attrs = manifest.getMainAttributes();
          return (String) attrs.get(Attributes.Name.MAIN_CLASS);
      }
  
      public void runMain(String[] args) throws InvocationTargetException {
          try {
              mainMethod.invoke(null, new Object[]{args});
          } catch (IllegalAccessException e) {
              IllegalStateException ex = new IllegalStateException("Unable to invoke main");
              ex.initCause(e);
              throw ex;
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/AppClientMBean.java
  
  Index: AppClientMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.client;
  
  import java.lang.reflect.InvocationTargetException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public interface AppClientMBean {
      public void runMain(String[] args) throws InvocationTargetException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/ClientDeploymentPlanner.java
  
  Index: ClientDeploymentPlanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.client;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.JarURLConnection;
  import java.net.URL;
  import java.util.Set;
  import java.util.jar.Attributes;
  import java.util.jar.Manifest;
  
  import org.apache.geronimo.deployment.DeploymentException;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public class ClientDeploymentPlanner implements ClientDeploymentPlannerMBean {
      public boolean plan(Set goals, Set plans) throws DeploymentException {
          return false;
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/ClientDeploymentPlannerMBean.java
  
  Index: ClientDeploymentPlannerMBean.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.client;
  
  import org.apache.geronimo.deployment.DeploymentPlanner;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public interface ClientDeploymentPlannerMBean extends DeploymentPlanner {
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/client/Launcher.java
  
  Index: Launcher.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.client;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Iterator;
  import java.util.Set;
  import javax.management.InstanceAlreadyExistsException;
  import javax.management.InstanceNotFoundException;
  import javax.management.MBeanException;
  import javax.management.MBeanRegistrationException;
  import javax.management.MBeanServer;
  import javax.management.NotCompliantMBeanException;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  import javax.management.ReflectionException;
  import javax.management.ServiceNotFoundException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.impl.LogFactoryImpl;
  import org.apache.geronimo.deployment.DeploymentException;
  import org.apache.geronimo.jmx.JMXKernel;
  import org.apache.geronimo.jmx.JMXUtil;
  
  /**
   * Launcher for J2EE Application Clients.
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public class Launcher {
      static {
          // Add our default Commons Logger that support the trace level
          if (System.getProperty(LogFactoryImpl.LOG_PROPERTY) == null) {
              System.setProperty(LogFactoryImpl.LOG_PROPERTY, "org.apache.geronimo.core.log.Log4jLog");
          }
      }
  
      private static final Log log = LogFactory.getLog("Geronimo Client");
      private static final String USAGE = "usage: " + Launcher.class.getName() + " <client.jar>
[application args]";
      private static final String[] DEPLOY_ARG_TYPES = new String[]{"java.net.URL"};
  
      private JMXKernel kernel;
      private MBeanServer mbServer;
      private URL clientURL;
      private String[] appArgs;
      private ObjectName controllerName;
      private ObjectName clientName;
  
      private Launcher(String[] args) throws IllegalArgumentException {
          parseCommandLine(args);
      }
  
      private void deploy() throws DeploymentException {
          Runtime.getRuntime().addShutdownHook(new ShutdownThread("Geronimo-Shutdown", this));
  
          kernel = new JMXKernel("Geronimo Client");
          mbServer = kernel.getMBeanServer();
          URL mletURL;
          try {
              mletURL = new URL("file:src/conf/client.mlet");
          } catch (MalformedURLException e) {
              throw new IllegalStateException("Unable to boot client.mlet");
          }
          Set bootedMBeans;
          try {
              bootedMBeans = kernel.bootMLet(mletURL);
          } catch (ServiceNotFoundException e) {
              throw new IllegalStateException("Could not load " + mletURL);
          }
  
          // check they all started OK and it included a controller and service planner
          ObjectName controllerPattern = JMXUtil.getObjectName("*:role=DeploymentController,*");
          ObjectName plannerPattern = JMXUtil.getObjectName("*:role=DeploymentPlanner,type=Client,*");
          boolean planner = false;
          for (Iterator i = bootedMBeans.iterator(); i.hasNext();) {
              Object o = i.next();
              if (o instanceof ObjectInstance) {
                  ObjectName mletName = ((ObjectInstance) o).getObjectName();
                  if (controllerPattern.apply(mletName)) {
                      if (controllerName != null) {
                          throw new DeploymentException("Multiple DeploymentControllers specified
in boot mlet");
                      }
                      controllerName = mletName;
                  } else if (plannerPattern.apply(mletName)) {
                      planner = true;
                  }
              } else if (o instanceof DeploymentException) {
                  throw (DeploymentException) o;
              } else if (o instanceof RuntimeException) {
                  throw (RuntimeException) o;
              } else if (o instanceof Error) {
                  throw (Error) o;
              } else {
                  throw new DeploymentException((Exception) o);
              }
          }
          if (controllerName == null) {
              throw new DeploymentException("Boot mlet did not load a DeploymentController");
          } else if (!planner) {
              throw new DeploymentException("Boot mlet did not load a DeploymentPlanner for
type=Service");
          }
  
          log.info("Deploying Application Client from " + clientURL);
          // @todo use the deployer to create the app client rather than doing it by hand
  //        try {
  //            mbServer.invoke(controllerName, "deploy", new Object[]{clientURL}, DEPLOY_ARG_TYPES);
  //        } catch (InstanceNotFoundException e) {
  //            throw new DeploymentException(e);
  //        } catch (MBeanException e) {
  //            throw new DeploymentException(e);
  //        } catch (ReflectionException e) {
  //            throw new DeploymentException(e);
  //        }
  
          AppClient clientMBean = new AppClient(clientURL);
          clientName = JMXUtil.getObjectName("geronimo.client:url=" + ObjectName.quote(clientURL.toString()));
          try {
              mbServer.registerMBean(clientMBean, clientName);
          } catch (MBeanRegistrationException e) {
              Exception targetException = e.getTargetException();
              if (targetException instanceof DeploymentException) {
                  throw (DeploymentException) targetException;
              }
              throw new DeploymentException(targetException);
          } catch (InstanceAlreadyExistsException e) {
              throw new DeploymentException(e);
          } catch (NotCompliantMBeanException e) {
              throw new DeploymentException(e);
          }
      }
  
      private void undeploy() {
          if (kernel != null) {
              if (controllerName != null) {
                  MBeanServer mbServer = kernel.getMBeanServer();
                  try {
                      mbServer.invoke(controllerName, "undeploy", new Object[]{clientURL},
DEPLOY_ARG_TYPES);
                  } catch (InstanceNotFoundException e) {
                      log.error("Error undeploying client", e);
                  } catch (MBeanException e) {
                      log.error("Error undeploying client", e);
                  } catch (ReflectionException e) {
                      log.error("Error undeploying client", e);
                  }
              }
              kernel.release();
          }
      }
  
      public void run() {
          try {
              mbServer.invoke(clientName, "runMain", new Object[]{appArgs}, new String[]{appArgs.getClass().getName()});
          } catch (InstanceNotFoundException e) {
              IllegalStateException ex = new IllegalStateException("Unable to invoke app client");
              ex.initCause(e);
              throw ex;
          } catch (MBeanException e) {
              log.error("Application threw Exception", e.getCause());
              return;
          } catch (ReflectionException e) {
              IllegalStateException ex = new IllegalStateException("Unable to invoke app client");
              ex.initCause(e);
              throw ex;
          }
      }
  
      public static void main(String[] args) {
          Launcher launcher;
          try {
              launcher = new Launcher(args);
          } catch (IllegalArgumentException e) {
              System.err.println(e.getMessage());
              System.exit(1);
              return;
          }
  
          try {
              launcher.deploy();
          } catch (DeploymentException e) {
              e.printStackTrace();
              System.exit(2);
              return;
          }
  
          launcher.run();
      }
  
      private void parseCommandLine(String[] args) throws IllegalArgumentException {
          if (args.length < 1) {
              throw new IllegalArgumentException(USAGE);
          }
          try {
              clientURL = new URL(args[0]);
          } catch (MalformedURLException e) {
              // wasn't a valid URL - see if it is a filename
              File file = new File(args[0]);
              if (!file.exists()) {
                  throw new IllegalArgumentException("File does not exist: " + file.getPath());
              }
              try {
                  clientURL = file.toURL();
              } catch (MalformedURLException e1) {
                  throw new IllegalArgumentException("Could not convert to URL: " + args[0]);
              }
          }
          appArgs = new String[args.length - 1];
          System.arraycopy(args, 1, appArgs, 0, args.length - 1);
      }
  
      private static class ShutdownThread extends Thread {
          private final Launcher launcher;
  
          private ShutdownThread(String name, Launcher launcher) {
              super(name);
              this.launcher = launcher;
          }
  
          public void run() {
              launcher.undeploy();
          }
      }
  }
  
  
  
  1.6       +2 -2      incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentController.java
  
  Index: DeploymentController.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentController.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DeploymentController.java	14 Aug 2003 00:02:34 -0000	1.5
  +++ DeploymentController.java	16 Aug 2003 19:03:09 -0000	1.6
  @@ -111,7 +111,7 @@
           relationService = JMXUtil.getRelationService(server);
           RoleInfo[] roleInfo = {
               new RoleInfo("DeploymentController", getClass().getName()),
  -            new RoleInfo("DeploymentPlanner", "org.apache.geronimo.deployment.DeploymentPlannerMBean",
true, true, 0, RoleInfo.ROLE_CARDINALITY_INFINITY, null)
  +            new RoleInfo("DeploymentPlanner", "org.apache.geronimo.deployment.DeploymentPlanner",
true, true, 0, RoleInfo.ROLE_CARDINALITY_INFINITY, null)
           };
           relationService.createRelationType("DeploymentController-DeploymentPlanner", roleInfo);
   
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/DeploymentPlanner.java
  
  Index: DeploymentPlanner.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.deployment;
  
  import java.util.Set;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public interface DeploymentPlanner {
      boolean plan(Set goals, Set plans) throws DeploymentException;
  }
  
  
  
  1.2       +3 -3      incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/service/ServiceDeploymentPlannerMBean.java
  
  Index: ServiceDeploymentPlannerMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/service/ServiceDeploymentPlannerMBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServiceDeploymentPlannerMBean.java	11 Aug 2003 17:59:11 -0000	1.1
  +++ ServiceDeploymentPlannerMBean.java	16 Aug 2003 19:03:09 -0000	1.2
  @@ -55,12 +55,12 @@
    */
   package org.apache.geronimo.deployment.service;
   
  -import org.apache.geronimo.deployment.DeploymentPlannerMBean;
  +import org.apache.geronimo.deployment.DeploymentPlanner;
   
   /**
    *
    *
    * @version $Revision$ $Date$
    */
  -public interface ServiceDeploymentPlannerMBean extends DeploymentPlannerMBean {
  +public interface ServiceDeploymentPlannerMBean extends DeploymentPlanner {
   }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/jmx/JMXKernel.java
  
  Index: JMXKernel.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  package org.apache.geronimo.jmx;
  
  import java.net.URL;
  import java.util.Set;
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  import javax.management.ServiceNotFoundException;
  import javax.management.loading.MLet;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2003/08/16 19:03:09 $
   */
  public class JMXKernel {
      private static final Log log = LogFactory.getLog(JMXKernel.class);
      private final MBeanServer server;
  
      public JMXKernel(String domainName) {
          server = MBeanServerFactory.createMBeanServer(domainName);
      }
  
      public void release() {
          MBeanServerFactory.releaseMBeanServer(server);
      }
  
      public MBeanServer getMBeanServer() {
          return server;
      }
  
      public Set bootMLet(URL mletURL) throws ServiceNotFoundException {
          String urlString = mletURL.toString();
          log.info("Booting MLets from URL " + urlString);
  
          ObjectName objectName;
          try {
              objectName = new ObjectName("geronimo.boot:type=BootMLet,bootURL=" + ObjectName.quote(urlString));
          } catch (MalformedObjectNameException e) {
              IllegalArgumentException ex = new IllegalArgumentException(e.getMessage());
              ex.initCause(e);
              throw ex;
          }
  
  
          MLet bootMLet = new MLet();
          try {
              server.registerMBean(bootMLet, objectName);
          } catch (Exception e) {
              // it should be impossible for this registration to fail
              IllegalStateException ex = new IllegalStateException(e.getMessage());
              ex.initCause(e);
              throw ex;
          }
          return bootMLet.getMBeansFromURL(mletURL);
      }
  
  }
  
  
  

Mime
View raw message