mirror of https://github.com/apache/activemq.git
resolve https://issues.apache.org/activemq/browse/AMQ-2366 - new File needed on each lock attempt or master restart will see old lock history
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@808378 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
589f9241fe
commit
868965997c
|
@ -55,18 +55,23 @@ public class LockFile {
|
|||
}
|
||||
|
||||
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 @@ public class LockFile {
|
|||
}
|
||||
lock = null;
|
||||
}
|
||||
closeReadFile();
|
||||
|
||||
if( deleteOnUnlock ) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void closeReadFile() {
|
||||
// close the file.
|
||||
if (readFile != null) {
|
||||
try {
|
||||
|
@ -102,9 +115,6 @@ public class LockFile {
|
|||
readFile = null;
|
||||
}
|
||||
|
||||
if( deleteOnUnlock ) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue