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/assembly/src/plan system-plan.xml
Date Fri, 04 Jun 2004 17:27:00 GMT
jboynes     2004/06/04 10:27:00

  Modified:    modules/system/src/java/org/apache/geronimo/system/main
                        Daemon.java
               modules/kernel/src/java/org/apache/geronimo/kernel
                        Kernel.java KernelMBean.java
               modules/system/src/java/org/apache/geronimo/system/serverinfo
                        ServerInfo.java
               modules/assembly/src/plan system-plan.xml
  Added:       modules/system/src/java/org/apache/geronimo/system/configuration
                        FileConfigurationList.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        PersistentConfigurationList.java
  Log:
  Support persistence of running configuration list across reboots
  
  Revision  Changes    Path
  1.5       +17 -2     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Daemon.java	10 Mar 2004 09:59:31 -0000	1.4
  +++ Daemon.java	4 Jun 2004 17:27:00 -0000	1.5
  @@ -18,6 +18,7 @@
   package org.apache.geronimo.system.main;
   
   import java.io.ObjectInputStream;
  +import java.io.IOException;
   import java.net.URI;
   import java.net.URISyntaxException;
   import java.util.ArrayList;
  @@ -29,6 +30,7 @@
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.config.Configuration;
   import org.apache.geronimo.kernel.config.ConfigurationManager;
  +import org.apache.geronimo.kernel.config.PersistentConfigurationList;
   import org.apache.geronimo.kernel.log.GeronimoLogging;
   import org.apache.geronimo.system.url.GeronimoURLFactory;
   
  @@ -103,6 +105,7 @@
               Runtime.getRuntime().addShutdownHook(new Thread("Shutdown Thread") {
                   public void run() {
                       if (kernel.isRunning()) {
  +                        kernel.notifyShutdown();
                           try {
                               // stop this configuration first
                               kernel.stopGBean(configName);
  @@ -118,7 +121,19 @@
               // start this configuration
               kernel.startRecursiveGBean(configName);
   
  -            // load the rest of the configuration listed on the command line
  +            if (configs.isEmpty()) {
  +                // nothing explicit, see what was running before
  +                try {
  +                    configs = (List) kernel.invoke(PersistentConfigurationList.OBJECT_NAME,
"restore");
  +                } catch (IOException e) {
  +                    System.err.println("Unable to restore last known configurations");
  +                    e.printStackTrace();
  +                    kernel.shutdown();
  +                    System.exit(3);
  +                }
  +            }
  +
  +            // load the rest of the configurations
               try {
                   for (Iterator i = configs.iterator(); i.hasNext();) {
                       URI configID = (URI) i.next();
  
  
  
  1.1                  incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java
  
  Index: FileConfigurationList.java
  ===================================================================
  /**
   *
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.system.configuration;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.FileNotFoundException;
  import java.net.URI;
  import java.net.URISyntaxException;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Collections;
  import javax.management.ObjectName;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.gbean.GBean;
  import org.apache.geronimo.gbean.GBeanContext;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoFactory;
  import org.apache.geronimo.gbean.WaitingException;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.config.ConfigurationInfo;
  import org.apache.geronimo.kernel.config.NoSuchStoreException;
  import org.apache.geronimo.kernel.config.PersistentConfigurationList;
  import org.apache.geronimo.kernel.management.State;
  import org.apache.geronimo.system.serverinfo.ServerInfo;
  
  /**
   * GBean that saves a list of configurations, for example to allow
   * a server to restart automatically.
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/04 17:27:00 $
   */
  public class FileConfigurationList implements GBean, PersistentConfigurationList {
      private static final Log log = LogFactory.getLog(PersistentConfigurationList.class);
      private final Kernel kernel;
      private final ServerInfo serverInfo;
      private final String configFile;
      private File configList;
      private Runnable hook;
  
      public FileConfigurationList(Kernel kernel, ServerInfo serverInfo, String configDir)
{
          this.kernel = kernel;
          this.serverInfo = serverInfo;
          this.configFile = configDir;
      }
  
      public void setGBeanContext(GBeanContext context) {
      }
  
      public void doStart() throws WaitingException, Exception {
          configList = serverInfo.resolve(configFile);
          File parent = configList.getParentFile();
          if (!parent.isDirectory()) {
              if (!parent.mkdirs()) {
                  throw new IOException("Unable to create directory for list:" + parent);
              }
          }
          hook = new Runnable() {
              public void run() {
                  try {
                      save();
                  } catch (IOException e) {
                      log.error("Unable to save configuration on shutdown", e);
                  }
              }
          };
          kernel.registerShutdownHook(hook);
      }
  
      public void doStop() throws Exception {
          doFail();
      }
  
      public void doFail() {
          kernel.unregisterShutdownHook(hook);
          hook = null;
          configList = null;
      }
  
      public synchronized void save() throws IOException {
          BufferedWriter writer = new BufferedWriter(new FileWriter(configList));
          try {
              List stores = kernel.listConfigurationStores();
              for (Iterator i = stores.iterator(); i.hasNext();) {
                  ObjectName storeName = (ObjectName) i.next();
                  List configList = kernel.listConfigurations(storeName);
                  for (Iterator j = configList.iterator(); j.hasNext();) {
                      ConfigurationInfo info = (ConfigurationInfo) j.next();
                      if (info.getState() == State.RUNNING) {
                          writer.write(info.getConfigID().toString());
                          writer.newLine();
                      }
                  }
              }
              writer.close();
          } catch (NoSuchStoreException e) {
              writer.close();
              configList.delete();
          }
          log.info("Saved running configuration list");
      }
  
      public List restore() throws IOException {
          FileReader fileReader;
          try {
              fileReader = new FileReader(configList);
          } catch (FileNotFoundException e) {
              return Collections.EMPTY_LIST;
          }
          BufferedReader reader = new BufferedReader(fileReader);
          try {
              List configs = new ArrayList();
              String line;
              while ((line = reader.readLine()) != null) {
                  try {
                      configs.add(new URI(line));
                  } catch (URISyntaxException e) {
                      throw new IOException("Invalid URI in config list: " + line);
                  }
              }
              return configs;
          } finally {
              reader.close();
          }
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoFactory infoFactory = new GBeanInfoFactory(FileConfigurationList.class);
          infoFactory.addInterface(PersistentConfigurationList.class);
          infoFactory.addReference("Kernel", Kernel.class);
          infoFactory.addReference("ServerInfo", ServerInfo.class);
          infoFactory.addAttribute("ConfigFile", String.class, true);
          infoFactory.setConstructor(new String[]{"Kernel", "ServerInfo", "ConfigFile"});
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  
      public static GBeanInfo getGBeanInfo() {
          return GBEAN_INFO;
      }
  }
  
  
  
  1.32      +34 -2     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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Kernel.java	4 Jun 2004 04:35:20 -0000	1.31
  +++ Kernel.java	4 Jun 2004 17:27:00 -0000	1.32
  @@ -24,8 +24,9 @@
   import java.net.URI;
   import java.util.Collections;
   import java.util.Hashtable;
  -import java.util.Map;
  +import java.util.LinkedList;
   import java.util.List;
  +import java.util.Map;
   import java.util.Set;
   import javax.management.Attribute;
   import javax.management.InstanceAlreadyExistsException;
  @@ -92,6 +93,7 @@
       private transient Log log;
       private transient boolean running;
       private transient MBeanServer mbServer;
  +    private transient LinkedList shutdownHooks = new LinkedList();
   
       private transient ConfigurationManager configurationManager;
       private transient GBeanMBean configurationManagerGBean;
  @@ -358,6 +360,36 @@
   
           running = true;
           log.info("Booted");
  +    }
  +
  +    public void registerShutdownHook(Runnable hook) {
  +        assert hook != null : "Shutdown hook was null";
  +        synchronized (shutdownHooks) {
  +            shutdownHooks.add(hook);
  +        }
  +    }
  +
  +    public void unregisterShutdownHook(Runnable hook) {
  +        synchronized (shutdownHooks) {
  +            shutdownHooks.remove(hook);
  +        }
  +    }
  +
  +    /**
  +     * @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);
  +            }
  +        }
       }
   
       /**
  
  
  
  1.13      +5 -1      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java
  
  Index: KernelMBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/KernelMBean.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- KernelMBean.java	4 Jun 2004 04:35:20 -0000	1.12
  +++ KernelMBean.java	4 Jun 2004 17:27:00 -0000	1.13
  @@ -132,4 +132,8 @@
        * @return a Set<ObjectName> of the names of online GBeans that match the query
        */
       Set listGBeans(ObjectName query);
  +
  +    void registerShutdownHook(Runnable hook);
  +
  +    void unregisterShutdownHook(Runnable hook);
   }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/PersistentConfigurationList.java
  
  Index: PersistentConfigurationList.java
  ===================================================================
  /**
   *
   *  Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.apache.geronimo.kernel.config;
  
  import java.io.IOException;
  import java.util.List;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  
  /**
   *
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/04 17:27:00 $
   */
  public interface PersistentConfigurationList {
      public static final ObjectName OBJECT_NAME = JMXUtil.getObjectName("geronimo.boot:role=PersistentConfigurationList");
  
      void save() throws IOException;
  
      List restore() throws IOException;
  }
  
  
  
  1.9       +6 -1      incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
  
  Index: ServerInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ServerInfo.java	2 Jun 2004 05:33:05 -0000	1.8
  +++ ServerInfo.java	4 Jun 2004 17:27:00 -0000	1.9
  @@ -74,6 +74,10 @@
           return file.getAbsolutePath();
       }
   
  +    public File resolve(final String filename) {
  +        return new File(base, filename);
  +    }
  +
       public URI resolve(final URI uri) {
           return baseURI.resolve(uri);
       }
  @@ -110,6 +114,7 @@
           infoFactory.addAttribute("Copyright", String.class, false);
   
           infoFactory.addOperation("resolvePath", new Class[]{String.class});
  +        infoFactory.addOperation("resolve", new Class[]{String.class});
           infoFactory.addOperation("resolve", new Class[]{URI.class});
   
           infoFactory.setConstructor(new String[]{"BaseDirectory"});
  
  
  
  1.8       +8 -1      incubator-geronimo/modules/assembly/src/plan/system-plan.xml
  
  Index: system-plan.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/assembly/src/plan/system-plan.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- system-plan.xml	30 May 2004 18:58:59 -0000	1.7
  +++ system-plan.xml	4 Jun 2004 17:27:00 -0000	1.8
  @@ -34,13 +34,20 @@
       <!-- ServerInfo service -->
       <gbean name="geronimo.system:role=ServerInfo" class="org.apache.geronimo.system.serverinfo.ServerInfo"/>
   
  -    <!-- ServerInfo service -->
  +    <!-- URLFactory service -->
       <gbean name="geronimo.system:role=URLFactory" class="org.apache.geronimo.system.url.GeronimoURLFactory"/>
   
       <!-- Configuration Store service -->
       <gbean name="geronimo.system:role=ConfigurationStore,type=Local" class="org.apache.geronimo.system.configuration.LocalConfigStore">
           <attribute name="root" type="java.net.URI">config-store</attribute>
           <reference name="ServerInfo">geronimo.system:role=ServerInfo</reference>
  +    </gbean>
  +
  +    <!-- Persistent List of running Configurations service -->
  +    <gbean name="geronimo.boot:role=PersistentConfigurationList" class="org.apache.geronimo.system.configuration.FileConfigurationList">
  +        <reference name="Kernel">geronimo.boot:role=Kernel</reference>
  +        <reference name="ServerInfo">geronimo.system:role=ServerInfo</reference>
  +        <attribute name="ConfigFile" type="java.lang.String">var/config/config.list</attribute>
       </gbean>
   
       <!-- Repository -->
  
  
  

Mime
View raw message