felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r808164 - in /felix/trunk/main/src/main: java/org/apache/felix/main/Main.java resources/config.properties
Date Wed, 26 Aug 2009 19:46:52 GMT
Author: rickhall
Date: Wed Aug 26 19:46:51 2009
New Revision: 808164

URL: http://svn.apache.org/viewvc?rev=808164&view=rev
Log:
Add shutdown hook to launcher. (FELIX-1478)

Modified:
    felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
    felix/trunk/main/src/main/resources/config.properties

Modified: felix/trunk/main/src/main/java/org/apache/felix/main/Main.java
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/java/org/apache/felix/main/Main.java?rev=808164&r1=808163&r2=808164&view=diff
==============================================================================
--- felix/trunk/main/src/main/java/org/apache/felix/main/Main.java (original)
+++ felix/trunk/main/src/main/java/org/apache/felix/main/Main.java Wed Aug 26 19:46:51 2009
@@ -44,6 +44,11 @@
     public static final String BUNDLE_DIR_SWITCH = "-b";
 
     /**
+     * The property name used to specify whether the launcher should
+     * install a shutdown hook.
+    **/
+    public static final String SHUTDOWN_HOOK_PROP = "felix.shutdown.hook";
+    /**
      * The property name used to specify an URL to the system
      * property file.
     **/
@@ -228,6 +233,30 @@
             configProps.setProperty(Constants.FRAMEWORK_STORAGE, cacheDir);
         }
 
+        // If enabled, register a shutdown hook to make sure the framework is
+        // cleanly shutdown when the VM exits.
+        String enableHook = configProps.getProperty(SHUTDOWN_HOOK_PROP);
+        if ((enableHook == null) || !enableHook.equalsIgnoreCase("false"))
+        {
+            Runtime.getRuntime().addShutdownHook(new Thread() {
+                public void run()
+                {
+                    try
+                    {
+                        if (m_fwk != null)
+                        {
+                            m_fwk.stop();
+                            m_fwk.waitForStop(0);
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        System.err.println("Error stopping framework: " + ex);
+                    }
+                }
+            });
+        }
+
         // Print welcome banner.
         System.out.println("\nWelcome to Felix");
         System.out.println("================\n");

Modified: felix/trunk/main/src/main/resources/config.properties
URL: http://svn.apache.org/viewvc/felix/trunk/main/src/main/resources/config.properties?rev=808164&r1=808163&r2=808164&view=diff
==============================================================================
--- felix/trunk/main/src/main/resources/config.properties (original)
+++ felix/trunk/main/src/main/resources/config.properties Wed Aug 26 19:46:51 2009
@@ -83,6 +83,10 @@
 # uncomment the following line to not install them.
 #felix.service.urlhandlers=false
 
+# The launcher registers a shutdown hook to cleanly stop the framework
+# by default, uncomment the following line to disable it.
+#felix.shutdown.hook=false
+
 #
 # Bundle config properties.
 #



Mime
View raw message