| | |
| | | |
| | | |
| | | // Open the file for reading and get the corresponding file channel. |
| | | FileChannel channel; |
| | | FileChannel channel = null; |
| | | RandomAccessFile raf = null; |
| | | try |
| | | { |
| | | RandomAccessFile raf = new RandomAccessFile(lockFile, "r"); |
| | | raf = new RandomAccessFile(lockFile, "r"); |
| | | channel = raf.getChannel(); |
| | | } |
| | | catch (Exception e) |
| | |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_OPEN; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | | stackTraceToSingleLineString(e))); |
| | | |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_LOCK; |
| | | failureReason.append(getMessage(msgID, |
| | | stackTraceToSingleLineString(e))); |
| | | if (channel != null) |
| | | { |
| | | try |
| | | { |
| | | channel.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_FILELOCKER_LOCK_SHARED_NOT_GRANTED; |
| | | failureReason.append(getMessage(msgID, lockFile)); |
| | | if (channel != null) |
| | | { |
| | | try |
| | | { |
| | | channel.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | else |
| | |
| | | |
| | | |
| | | // Open the file read+write and get the corresponding file channel. |
| | | FileChannel channel; |
| | | FileChannel channel = null; |
| | | RandomAccessFile raf = null; |
| | | try |
| | | { |
| | | RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); |
| | | raf = new RandomAccessFile(lockFile, "rw"); |
| | | channel = raf.getChannel(); |
| | | } |
| | | catch (Exception e) |
| | |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | | stackTraceToSingleLineString(e))); |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK; |
| | | failureReason.append(getMessage(msgID, lockFile, |
| | | stackTraceToSingleLineString(e))); |
| | | if (channel != null) |
| | | { |
| | | try |
| | | { |
| | | channel.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | |
| | | { |
| | | int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_NOT_GRANTED; |
| | | failureReason.append(getMessage(msgID, lockFile)); |
| | | if (channel != null) |
| | | { |
| | | try |
| | | { |
| | | channel.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (raf != null) |
| | | { |
| | | try |
| | | { |
| | | raf.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | else |