karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1056254 - in /karaf/branches/karaf-2.1.x: main/src/main/java/org/apache/karaf/main/Main.java shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java
Date Fri, 07 Jan 2011 11:01:27 GMT
Author: gnodet
Date: Fri Jan  7 11:01:26 2011
New Revision: 1056254

URL: http://svn.apache.org/viewvc?rev=1056254&view=rev
Log:
[KARAF-327] Add a property to control the framework factory in case multiples ones are available
in the classloader, do the call to framework.stop() in a new thread to avoid blocking (even
though the shutdown itself does not block, felix waits for a lock and that can take some time),
also report the error if a timeout occurs using the wrapper

Modified:
    karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java
    karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java

Modified: karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java?rev=1056254&r1=1056253&r2=1056254&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java (original)
+++ karaf/branches/karaf-2.1.x/main/src/main/java/org/apache/karaf/main/Main.java Fri Jan
 7 11:01:26 2011
@@ -38,6 +38,7 @@ import java.util.regex.Pattern;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.ServiceReference;
@@ -146,6 +147,8 @@ public class Main {
     
     public static final String KARAF_FRAMEWORK = "karaf.framework";
 
+    public static final String KARAF_FRAMEWORK_FACTORY = "karaf.framework.factory";
+
     public static final String KARAF_SHUTDOWN_TIMEOUT = "karaf.shutdown.timeout";
 
     public static final String KARAF_SHUTDOWN_PORT = "karaf.shutdown.port";
@@ -239,10 +242,13 @@ public class Main {
         shutdownTimeout = Integer.parseInt(configProps.getProperty(KARAF_SHUTDOWN_TIMEOUT,
Integer.toString(shutdownTimeout)));
         // Start up the OSGI framework
 
-        InputStream is = classLoader.getResourceAsStream("META-INF/services/" + FrameworkFactory.class.getName());
-        BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-        String factoryClass = br.readLine();
-        br.close();
+        String factoryClass = configProps.getProperty(KARAF_FRAMEWORK_FACTORY);
+        if (factoryClass == null) {
+            InputStream is = classLoader.getResourceAsStream("META-INF/services/" + FrameworkFactory.class.getName());
+            BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+            factoryClass = br.readLine();
+            br.close();
+        }
         FrameworkFactory factory = (FrameworkFactory) classLoader.loadClass(factoryClass).newInstance();
         framework = factory.newFramework(new StringMap(configProps, false));
         framework.start();
@@ -279,7 +285,15 @@ public class Main {
             // Stop the framework in case it's still active
             exiting = true;
             if (framework.getState() == Bundle.ACTIVE) {
-                framework.stop();
+                new Thread() {
+                    public void run() {
+                        try {
+                            framework.stop();
+                        } catch (BundleException e) {
+                            System.err.println("Error stopping karaf: " + e.getMessage());
+                        }
+                    }
+                }.start();
             }
 
             int timeout = shutdownTimeout;

Modified: karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java?rev=1056254&r1=1056253&r2=1056254&view=diff
==============================================================================
--- karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java
(original)
+++ karaf/branches/karaf-2.1.x/shell/wrapper/src/main/java/org/apache/karaf/shell/wrapper/Main.java
Fri Jan  7 11:01:26 2011
@@ -100,7 +100,11 @@ public class Main extends Thread impleme
         try
         {
             destroying = true;
-            main.destroy();
+            if (!main.destroy())
+            {
+                System.err.println("Timeout waiting for Karaf to shutdown");
+                return -3;
+            }
         }
         catch (Throwable ex)
         {



Mime
View raw message