activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r808378 - /activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java
Date Thu, 27 Aug 2009 11:46:21 GMT
Author: gtully
Date: Thu Aug 27 11:46:21 2009
New Revision: 808378

URL: http://svn.apache.org/viewvc?rev=808378&view=rev
Log:
resolve https://issues.apache.org/activemq/browse/AMQ-2366 - new File needed on each lock
attempt or master restart will see old lock history

Modified:
    activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java

Modified: activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java
URL: http://svn.apache.org/viewvc/activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java?rev=808378&r1=808377&r2=808378&view=diff
==============================================================================
--- activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java (original)
+++ activemq/trunk/kahadb/src/main/java/org/apache/kahadb/util/LockFile.java Thu Aug 27 11:46:21
2009
@@ -55,18 +55,23 @@
         }
         
         IOHelper.mkdirs(file.getParentFile());
-        if (readFile == null) {
-            readFile = new RandomAccessFile(file, "rw");
-        }
+        
         if (lock == null) {
+            readFile = new RandomAccessFile(file, "rw");
+            IOException reason = null;
             try {
                 lock = readFile.getChannel().tryLock();
             } catch (OverlappingFileLockException e) {
-                throw IOExceptionSupport.create("File '" + file + "' could not be locked.",e);
+                reason = IOExceptionSupport.create("File '" + file + "' could not be locked.",e);
             }
             if (lock != null) {
                 lockCounter++;
             } else {
+                // new read file for next attempt
+                closeReadFile();
+                if (reason != null) {
+                    throw reason;
+                }
                 throw new IOException("File '" + file + "' could not be locked.");
             }
               
@@ -93,6 +98,14 @@
             }
             lock = null;
         }
+        closeReadFile();
+        
+        if( deleteOnUnlock ) {
+            file.delete();
+        }
+    }
+
+    private void closeReadFile() {
         // close the file.
         if (readFile != null) {
             try {
@@ -102,9 +115,6 @@
             readFile = null;
         }
         
-        if( deleteOnUnlock ) {
-            file.delete();
-        }
     }
 
 }



Mime
View raw message