You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/12/20 18:41:02 UTC
[3/3] git commit: CAMEL-7088: Close resources in file read lock.
Thanks to Leonid Marushevskiy for the patch.
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/84573258
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/84573258
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/84573258
Branch: refs/heads/camel-2.11.x
Commit: 84573258602f5f8af4a211ee4ab17eac07848880
Parents: c321cb8
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Dec 20 18:43:18 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Dec 20 18:43:56 2013 +0100
----------------------------------------------------------------------
.../file/strategy/FileLockExclusiveReadLockStrategy.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/84573258/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 11f370b..f085b56 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
@@ -58,9 +58,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();
@@ -107,6 +110,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;
@@ -124,7 +130,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);
}
}
}