/** * Create the lock file if it doesn't already exist and lock it with * an exclusive lock. * * @param lockFileName the name of the lock file * @return the FileLock object representing the lock file * @throws IOException if the file has already been locked or an I/O error * occurs. */ public static LockFile createLockFile( String lockFileName ) throws IOException { return createLockFile(new File(lockFileName)); }
protected void finalize() { if (lockFile != null) { logger.warn("In finalize. Lock file was not released: " + lockFile); } release(); }
/** * Create the lock file if it doesn't already exist and lock it with * an exclusive lock. * * @param lockFile the name of the lock file * @return the FileLock object representing the lock file * @throws IOException if the file has already been locked or an I/O error * occurs. */ public static LockFile createLockFile(File lockFile) throws IOException { return new LockFile(lockFile); }
/** * Create the lock file if it doesn't already exist and lock it with * an exclusive lock. * * @param lockFile the name of the lock file * @throws IOException if the file has already been locked or an I/O error * occurs. */ private LockFile(File lockFile) throws IOException { this.lockFile = lockFile; if (lockFile == null) { throw new IllegalArgumentException("Parameter lockFile is null"); } lockInternal(lockFile); try { raf = new RandomAccessFile(lockFile, "rw"); fc = raf.getChannel(); fl = fc.tryLock(); if (fl == null) throw new IOException("Lock file busy: " + lockFile); } finally { if (fl == null) { // An exception must have occurred. release(); } } }
/** * Releases and removes the lock file. */ public void release() { try { try { if (fl != null) fl.release(); } finally { if (fc != null) fc.close(); if (raf != null) raf.close(); } } catch (IOException ex) { logger.warn("I/O exception while releasing lock file: " + lockFile, ex); } finally { if (lockFile != null) { lockFile.delete(); unlockInternal(lockFile); lockFile = null; } fl = null; fc = null; raf = null; } }
} finally { if (lockFile != null) { lockFile.release(); lockFile = null;
this.fileName = fileName; lockFile = LockFile.createLockFile(fileName + ".np.lock");
freeList = null; if (lockFile != null) { lockFile.release(); lockFile = null;
this.fileName = fileName; lockFile = LockFile.createLockFile(fileName + ".sp.lock");
lockFile.release(); lockFile = null;