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/kernel/src/java/org/apache/geronimo/kernel Kernel.java
Date Sat, 05 Jun 2004 19:30:43 GMT
jboynes     2004/06/05 12:30:43

  Modified:    modules/kernel/src/test/org/apache/geronimo/kernel
                        BootstrapTest.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        ConfigurationManagerImpl.java
               modules/system/src/java/org/apache/geronimo/system/main
                        Daemon.java
               modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java
  Log:
  Have kernel shutdown automatically stop all the configurations
  Removed Serializable from Kernel as we aren't saving state that way any more
  
  Revision  Changes    Path
  1.8       +1 -26     incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/BootstrapTest.java
  
  Index: BootstrapTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/BootstrapTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- BootstrapTest.java	10 Mar 2004 09:59:02 -0000	1.7
  +++ BootstrapTest.java	5 Jun 2004 19:30:43 -0000	1.8
  @@ -18,10 +18,6 @@
   package org.apache.geronimo.kernel;
   
   import java.io.File;
  -import java.io.FileInputStream;
  -import java.io.FileOutputStream;
  -import java.io.ObjectInputStream;
  -import java.io.ObjectOutputStream;
   
   import junit.framework.TestCase;
   
  @@ -36,27 +32,6 @@
   
       public void testCreate() throws Exception {
           Kernel kernel = new Kernel("test.kernel", "geronimo");
  -        assertEquals("No kernel should be registered", null, Kernel.getKernel("test.kernel"));
  -        kernel.boot();
  -        assertEquals("test.kernel kernel should be registered", kernel, Kernel.getKernel("test.kernel"));
  -        kernel.shutdown();
  -        assertEquals("No kernel should be registered", null, Kernel.getKernel("test.kernel"));
  -    }
  -
  -    public void testPersist() throws Exception {
  -        Kernel kernel = new Kernel("test.kernel", "geronimo");
  -        assertEquals("No kernel should be registered", null, Kernel.getKernel("test.kernel"));
  -        kernel.boot();
  -        assertEquals("test.kernel kernel should be registered", kernel, Kernel.getKernel("test.kernel"));
  -        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(kernelState));
  -        oos.writeObject(kernel);
  -        oos.close();
  -        kernel.shutdown();
  -        assertEquals("No kernel should be registered", null, Kernel.getKernel("test.kernel"));
  -
  -        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(kernelState));
  -        kernel = (Kernel) ois.readObject();
  -        ois.close();
           assertEquals("No kernel should be registered", null, Kernel.getKernel("test.kernel"));
           kernel.boot();
           assertEquals("test.kernel kernel should be registered", kernel, Kernel.getKernel("test.kernel"));
  
  
  
  1.7       +36 -7     incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java
  
  Index: ConfigurationManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationManagerImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConfigurationManagerImpl.java	5 Jun 2004 01:40:09 -0000	1.6
  +++ ConfigurationManagerImpl.java	5 Jun 2004 19:30:43 -0000	1.7
  @@ -22,8 +22,10 @@
   import java.net.URL;
   import java.util.ArrayList;
   import java.util.Collection;
  +import java.util.Iterator;
   import java.util.LinkedList;
   import java.util.List;
  +import java.util.Set;
   import javax.management.InstanceNotFoundException;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
  @@ -32,6 +34,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
  +import org.apache.geronimo.gbean.GBeanLifecycle;
   import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.jmx.JMXUtil;
  @@ -40,7 +43,7 @@
   /**
    * @version $Revision$ $Date$
    */
  -public class ConfigurationManagerImpl implements ConfigurationManager {
  +public class ConfigurationManagerImpl implements ConfigurationManager, GBeanLifecycle {
       private static final Log log = LogFactory.getLog(ConfigurationManagerImpl.class);
       private final Kernel kernel;
       private final Collection stores;
  @@ -195,15 +198,41 @@
       }
   
       private List getStores() {
  -        List storeSnapshot = new ArrayList(stores);
  -        if (storeSnapshot.size() == 0) {
  -            throw new UnsupportedOperationException("There are no installed ConfigurationStores");
  -        }
  -        return storeSnapshot;
  +        return new ArrayList(stores);
       }
   
       public ObjectName getConfigObjectName(URI configID) throws MalformedObjectNameException
{
           return new ObjectName("geronimo.config:name=" + ObjectName.quote(configID.toString()));
  +    }
  +
  +    public void doStart() {
  +    }
  +
  +    private static final ObjectName CONFIG_QUERY = JMXUtil.getObjectName("geronimo.config:*");
  +
  +    public void doStop() {
  +        while (true) {
  +            Set configs = kernel.listGBeans(CONFIG_QUERY);
  +            if (configs.isEmpty()) {
  +                return;
  +            }
  +            for (Iterator i = configs.iterator(); i.hasNext();) {
  +                ObjectName configName = (ObjectName) i.next();
  +                if (kernel.isLoaded(configName)) {
  +                    try {
  +                        kernel.stopGBean(configName);
  +                        kernel.unloadGBean(configName);
  +                    } catch (InstanceNotFoundException e) {
  +                        // ignore
  +                    } catch (InvalidConfigException e) {
  +                        // ignore
  +                    }
  +                }
  +            }
  +        }
  +    }
  +
  +    public void doFail() {
       }
   
       public static final GBeanInfo GBEAN_INFO;
  
  
  
  1.7       +5 -13     incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
  
  Index: Daemon.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Daemon.java	4 Jun 2004 17:38:45 -0000	1.6
  +++ Daemon.java	5 Jun 2004 19:30:43 -0000	1.7
  @@ -61,7 +61,6 @@
        * will remain running until the shutdown() method on the kernel is
        * invoked or until the JVM exits.
        * @param args the command line arguments
  -     * @todo save list of started configurations and restart them next time
        */
       public static void main(String[] args) {
           try {
  @@ -97,6 +96,7 @@
               } catch (Exception e) {
                   e.printStackTrace();
                   System.exit(2);
  +                throw new AssertionError();
               }
   
               // add our shutdown hook
  @@ -104,17 +104,7 @@
               final ObjectName configName = configurationManager.load(configuration, classLoader.getResource("/"));
               Runtime.getRuntime().addShutdownHook(new Thread("Shutdown Thread") {
                   public void run() {
  -                    if (kernel.isRunning()) {
  -                        kernel.notifyShutdown();
  -                        try {
  -                            // stop this configuration first
  -                            kernel.stopGBean(configName);
  -                        } catch (Exception e) {
  -                            // ignore
  -                        }
  -                        // clean up the kernel before exiting
  -                        kernel.shutdown();
  -                    }
  +                    kernel.shutdown();
                   }
               });
   
  @@ -131,6 +121,7 @@
                           e.printStackTrace();
                           kernel.shutdown();
                           System.exit(3);
  +                        throw new AssertionError();
                       }
                   }
               }
  @@ -149,6 +140,7 @@
                   kernel.shutdown();
                   e.printStackTrace();
                   System.exit(3);
  +                throw new AssertionError();
               }
   
   
  
  
  
  1.36      +43 -43    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java
  
  Index: Kernel.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/Kernel.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- Kernel.java	5 Jun 2004 01:40:09 -0000	1.35
  +++ Kernel.java	5 Jun 2004 19:30:43 -0000	1.36
  @@ -18,7 +18,6 @@
   package org.apache.geronimo.kernel;
   
   import java.io.IOException;
  -import java.io.Serializable;
   import java.lang.ref.ReferenceQueue;
   import java.lang.ref.WeakReference;
   import java.net.URI;
  @@ -72,7 +71,7 @@
    *
    * @version $Revision$ $Date$
    */
  -public class Kernel extends NotificationBroadcasterSupport implements Serializable, KernelMBean
{
  +public class Kernel extends NotificationBroadcasterSupport implements KernelMBean {
   
       /**
        * The JMX name used by a Kernel to register itself when it boots.
  @@ -90,13 +89,13 @@
       private final String kernelName;
       private final String domainName;
   
  -    private transient Log log;
  -    private transient boolean running;
  -    private transient MBeanServer mbServer;
  -    private transient LinkedList shutdownHooks = new LinkedList();
  +    private Log log;
  +    private boolean running;
  +    private MBeanServer mbServer;
  +    private LinkedList shutdownHooks = new LinkedList();
   
  -    private transient ConfigurationManager configurationManager;
  -    private transient GBeanMBean configurationManagerGBean;
  +    private ConfigurationManager configurationManager;
  +    private GBeanMBean configurationManagerGBean;
   
       private static final String[] NO_TYPES = new String[0];
       private static final Object[] NO_ARGS = new Object[0];
  @@ -379,23 +378,6 @@
       }
   
       /**
  -     * @deprecated this should be in shutdown
  -     */
  -    public void notifyShutdown() {
  -        while (!shutdownHooks.isEmpty()) {
  -            Runnable hook;
  -            synchronized (shutdownHooks) {
  -                hook = (Runnable) shutdownHooks.removeFirst();
  -            }
  -            try {
  -                hook.run();
  -            } catch (Throwable e) {
  -                log.warn("Error from kernel shutdown hook", e);
  -            }
  -        }
  -    }
  -
  -    /**
        * Shut down this kernel instance, unregistering the MBeans and releasing
        * the MBeanServer.
        */
  @@ -406,23 +388,8 @@
           running = false;
           log.info("Starting kernel shutdown");
   
  -        configurationManager = null;
  -        configurationManagerGBean = null;
  -        try {
  -            if (configurationManagerGBean != null) {
  -                configurationManagerGBean.stop();
  -            }
  -        } catch (Exception e) {
  -            // ignore
  -        }
  -        try {
  -            if (configurationManagerGBean != null) {
  -                mbServer.unregisterMBean(CONFIGURATION_MANAGER_NAME);
  -            }
  -        } catch (Exception e) {
  -            // ignore
  -        }
  -        configurationManagerGBean = null;
  +        notifyShutdownHooks();
  +        shutdownConfigManager();
   
           try {
               mbServer.unregisterMBean(KERNEL);
  @@ -446,6 +413,39 @@
           }
   
           log.info("Kernel shutdown complete");
  +    }
  +
  +    private void notifyShutdownHooks() {
  +        while (!shutdownHooks.isEmpty()) {
  +            Runnable hook;
  +            synchronized (shutdownHooks) {
  +                hook = (Runnable) shutdownHooks.removeFirst();
  +            }
  +            try {
  +                hook.run();
  +            } catch (Throwable e) {
  +                log.warn("Error from kernel shutdown hook", e);
  +            }
  +        }
  +    }
  +
  +    private void shutdownConfigManager() {
  +        configurationManager = null;
  +        try {
  +            if (configurationManagerGBean != null) {
  +                configurationManagerGBean.stop();
  +            }
  +        } catch (Exception e) {
  +            // ignore
  +        }
  +        try {
  +            if (configurationManagerGBean != null) {
  +                mbServer.unregisterMBean(CONFIGURATION_MANAGER_NAME);
  +            }
  +        } catch (Exception e) {
  +            // ignore
  +        }
  +        configurationManagerGBean = null;
       }
   
       public boolean isRunning() {
  
  
  

Mime
View raw message