geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r209997 - /geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java
Date Sun, 10 Jul 2005 06:19:31 GMT
Author: ammulder
Date: Sat Jul  9 23:19:29 2005
New Revision: 209997

URL: http://svn.apache.org/viewcvs?rev=209997&view=rev
Log:
Save the list of running configurations every time a configuration is
  started or stopped.  GERONIMO-657

Modified:
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java?rev=209997&r1=209996&r2=209997&view=diff
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java
(original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/FileConfigurationList.java
Sat Jul  9 23:19:29 2005
@@ -37,10 +37,11 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.lifecycle.LifecycleListener;
+import org.apache.geronimo.kernel.lifecycle.LifecycleAdapter;
 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.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.management.State;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
@@ -83,22 +84,45 @@
     private boolean kernelFullyStarted = false;
 
     /**
-     * The acutal absolute file where we write the configuration list.
+     * The actual absolute file where we write the configuration list.
      */
     private File configList;
 
     /**
-     * Our hook the kernel calls before shutting down.
+     * Listener to make this GBean save every time a configuration is started
+     * or stopped.
      */
-    private Runnable hook;
+    private LifecycleListener listener;
 
     public FileConfigurationList(Kernel kernel, ServerInfo serverInfo, ConfigurationManager
configurationManager, String configDir) {
         this.kernel = kernel;
         this.configurationManager = configurationManager;
         this.serverInfo = serverInfo;
         this.configFile = configDir;
+        this.listener = new LifecycleAdapter() {
+            public void stopped(ObjectName objectName) {
+                if(kernelFullyStarted && FileConfigurationList.this.kernel.isRunning())
{
+                    doSave();
+                }
+            }
+
+            public void running(ObjectName objectName) {
+                if(kernelFullyStarted && FileConfigurationList.this.kernel.isRunning())
{
+                    doSave();
+                }
+            }
+
+            private void doSave() {
+                try {
+                    save();
+                } catch (IOException e) {
+                    log.error("Unable to save list of running configurations", e);
+                }
+            }
+        };
     }
 
+
     public void doStart() throws Exception {
         configList = serverInfo.resolve(configFile);
         File parent = configList.getParentFile();
@@ -107,16 +131,7 @@
                 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);
+        kernel.getLifecycleMonitor().addLifecycleListener(listener, new ObjectName("geronimo.config:*"));
     }
 
     public void doStop() throws Exception {
@@ -124,8 +139,7 @@
     }
 
     public void doFail() {
-        kernel.unregisterShutdownHook(hook);
-        hook = null;
+        kernel.getLifecycleMonitor().removeLifecycleListener(listener);
         configList = null;
     }
 
@@ -139,7 +153,11 @@
 
     public synchronized void save() throws IOException {
         if (!kernelFullyStarted) {
-            log.info("Configuration list was not saved.  Kernel was never fully started.");
+            log.debug("Configuration list was not saved.  Kernel was never fully started.");
+            return;
+        }
+        if (!kernel.isRunning()) {
+            log.debug("Configuration list was not saved.  Kernel is shutting down.");
             return;
         }
 



Mime
View raw message