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-3648] Don't update instance.properties on shutdown, when stopped by root container
Date Thu, 18 Jun 2015 13:17:40 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-2.x 6740a8db4 -> 392dbc773


[KARAF-3648] Don't update instance.properties on shutdown, when stopped by root container


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

Branch: refs/heads/karaf-2.x
Commit: 392dbc7737edf1c3aa141a476272b96e47a1ece8
Parents: 6740a8d
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
Authored: Wed Jun 17 17:05:09 2015 +0200
Committer: Grzegorz Grzybek <gr.grzybek@gmail.com>
Committed: Wed Jun 17 17:05:09 2015 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/karaf/main/Main.java   | 24 ++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/392dbc77/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 ba0342b..90cff3c 100644
--- a/main/src/main/java/org/apache/karaf/main/Main.java
+++ b/main/src/main/java/org/apache/karaf/main/Main.java
@@ -27,10 +27,12 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
+import java.io.RandomAccessFile;
 import java.io.Writer;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
 import java.net.*;
+import java.nio.channels.FileLock;
 import java.security.AccessControlException;
 import java.security.Provider;
 import java.security.Security;
@@ -627,6 +629,28 @@ public class Main {
                         throw new Exception(se.getMessage());
                     }
                 }
+                // don't instance.properties if we're stopping and can't acquire lock
+                if (!isStartingInstance) {
+                    RandomAccessFile raf = new RandomAccessFile(propertiesFile, "rw");
+                    boolean proceed = true;
+                    try {
+                        FileLock lock = raf.getChannel().tryLock();
+                        if (lock == null) {
+                            proceed = false;
+                        } else {
+                            lock.release();
+                        }
+                    } finally {
+                        // if proceed is true than we got the lock or OverlappingFileLockException
+                        // but we may proceed in either case
+                        raf.close();
+                    }
+                    if (!proceed) {
+                        // we didn't acquire lock, it may mean that root container is holding
the lock when
+                        // stopping the child
+                        return;
+                    }
+                }
                 FileLockUtils.execute(propertiesFile, new FileLockUtils.RunnableWithProperties()
{
                     public void run(org.apache.felix.utils.properties.Properties props) throws
IOException {
                         if (props.isEmpty()) {


Mime
View raw message