camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] git commit: CAMEL-7088: Close resources in file read lock. Thanks to Leonid Marushevskiy for the patch.
Date Fri, 20 Dec 2013 17:41:00 GMT
Updated Branches:
  refs/heads/camel-2.11.x c321cb881 -> 845732586
  refs/heads/camel-2.12.x 5a3f2daca -> 0e3ed7f3d
  refs/heads/master a2f600851 -> 8ad63b860


CAMEL-7088: Close resources in file read lock. Thanks to Leonid Marushevskiy for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8ad63b86
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8ad63b86
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8ad63b86

Branch: refs/heads/master
Commit: 8ad63b86070909bbdf4ca45a8ebb2fd0602f5477
Parents: a2f6008
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Dec 20 18:43:18 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Dec 20 18:43:18 2013 +0100

----------------------------------------------------------------------
 .../file/strategy/FileLockExclusiveReadLockStrategy.java  | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8ad63b86/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
index e229b5f..1d0c4d7 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/strategy/FileLockExclusiveReadLockStrategy.java
@@ -63,9 +63,12 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
 
         LOG.trace("Waiting for exclusive read lock to file: {}", target);
 
+        FileChannel channel = null;
+        RandomAccessFile randomAccessFile = null;
         try {
+            randomAccessFile = new RandomAccessFile(target, "rw");
             // try to acquire rw lock on the file before we can consume it
-            FileChannel channel = new RandomAccessFile(target, "rw").getChannel();
+            channel = randomAccessFile.getChannel();
 
             boolean exclusive = false;
             StopWatch watch = new StopWatch();
@@ -113,6 +116,9 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
                 // we were interrupted while sleeping, we are likely being shutdown so return
false
                 return false;
             }
+        } finally {
+            IOHelper.close(channel, "while acquiring exclusive read lock for file: " + lockFileName,
LOG);
+            IOHelper.close(randomAccessFile, "while acquiring exclusive read lock for file:
" + lockFileName, LOG);
         }
 
         return true;
@@ -131,7 +137,7 @@ public class FileLockExclusiveReadLockStrategy extends MarkerFileExclusiveReadLo
                 lock.release();
             } finally {
                 // must close channel first
-                IOHelper.close(channel, "while acquiring exclusive read lock for file: "
+ lockFileName, LOG);
+                IOHelper.close(channel, "while releasing exclusive read lock for file: "
+ lockFileName, LOG);
             }
         }
     }


Mime
View raw message