karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-5315] Avoid race condition during SIGTERM
Date Wed, 20 Sep 2017 09:03:39 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x e9f338dee -> 00c1d82f9


[KARAF-5315] Avoid race condition during SIGTERM


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/00c1d82f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/00c1d82f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/00c1d82f

Branch: refs/heads/karaf-4.0.x
Commit: 00c1d82f9cc3fa567396146318d44736db8112ff
Parents: e9f338d
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Wed Sep 20 11:03:11 2017 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Wed Sep 20 11:03:11 2017 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/karaf/main/Main.java   | 24 +++++++++++++-------
 .../apache/karaf/main/lock/SimpleFileLock.java  |  6 ++---
 2 files changed, 19 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/00c1d82f/main/src/main/java/org/apache/karaf/main/Main.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/Main.java b/main/src/main/java/org/apache/karaf/main/Main.java
index 48dcb5b..e8f67c7 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -75,18 +75,17 @@ public class Main {
      */
     public static final String STARTUP_PROPERTIES_FILE_NAME = "startup.properties";
 
-
-    Logger LOG = Logger.getLogger(this.getClass().getName());
+    private static final Logger LOG = Logger.getLogger(Main.class.getName());
 
     private ConfigProperties config;
-    private Framework framework = null;
+    private Framework framework;
     private final String[] args;
     private int exitCode;
     private ShutdownCallback shutdownCallback;
     private KarafActivatorManager activatorManager;
-    private Lock lock;
-    private KarafLockCallback lockCallback;
-    private boolean exiting;
+    private volatile Lock lock;
+    private final KarafLockCallback lockCallback = new KarafLockCallback();
+    private volatile boolean exiting;
     
     /**
      * <p>
@@ -238,7 +237,6 @@ public class Main {
         }
         String log4jConfigPath = System.getProperty("karaf.etc") + "/org.ops4j.pax.logging.cfg";
         BootstrapLogManager.setProperties(config.props, log4jConfigPath);
-        lockCallback = new KarafLockCallback();
         InstanceHelper.updateInstancePid(config.karafHome, config.karafBase, true);
         LOG.addHandler(BootstrapLogManager.getDefaultHandler());
 
@@ -342,7 +340,17 @@ public class Main {
                 },
                 new InvocationHandler() {
                     public Object invoke(Object proxy, Method method, Object[] args) throws
Throwable {
-                        Main.this.destroy();
+                        new Thread() {
+                            @Override
+                            public void run() {
+                                try {
+                                    exiting = true;
+                                    framework.stop();
+                                } catch (BundleException e) {
+                                    e.printStackTrace();
+                                }
+                            }
+                        }.start();
                         return null;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/00c1d82f/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
----------------------------------------------------------------------
diff --git a/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java b/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
index 7004f7f..831aae2 100644
--- a/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
+++ b/main/src/main/java/org/apache/karaf/main/lock/SimpleFileLock.java
@@ -59,7 +59,7 @@ public class SimpleFileLock implements Lock {
         }
     }
 
-    public boolean lock() throws Exception {
+    public synchronized boolean lock() throws Exception {
         LOG.info("Trying to lock " + lockPath.getPath());
         if (lock == null) {
             lock = lockFile.getChannel().tryLock();
@@ -72,7 +72,7 @@ public class SimpleFileLock implements Lock {
         return lock != null;
     }
 
-    public void release() throws Exception {
+    public synchronized void release() throws Exception {
         if (lock != null && lock.isValid()) {
             LOG.info("Releasing lock " + lockPath.getPath());
             lock.release();
@@ -81,7 +81,7 @@ public class SimpleFileLock implements Lock {
         lock = null;
     }
  
-    public boolean isAlive() throws Exception {
+    public synchronized boolean isAlive() throws Exception {
         return lock != null && lock.isValid() && lockPath.exists();
     }
 


Mime
View raw message