/** * Unlock directory. * * @throws IOException */ private void unlock(File dir) throws IOException { FileLock lock = locks.remove(dir.getAbsolutePath()); if (lock == null) { return; } lock.release(); lock.channel().close(); lock = null; }
/** * Flushes and closes all opened files. */ @Override public void close() { // release locks super.close(); allLocks.remove(fileName); try { FileChannel channel = lock.channel(); lock.release(); channel.close(); File file = new File(fileName + LCK_EXT); file.delete(); } catch (IOException e) { // ignore } }
void closeLockFile() { FileLock myfl = this.fl; if (myfl != null) { try { FileChannel fc = myfl.channel(); if (myfl.isValid()) { myfl.release(); } fc.close(); } catch (IOException ignore) { } this.fl = null; } File f = this.lockFile; if (f != null) { if (f.delete()) { if (logger.isDebugEnabled()) { logger.debug("Deleted lock file {}", f); } } else if (f.exists()) { if (logger.isDebugEnabled()) { logger.debug("Could not delete lock file {}", f); } } } if (logger.isDebugEnabled()) { logger.debug("Unlocked disk store {}", name); } }
/** * Lock storage to provide exclusive access. * <p> * <p> Locking is not supported by all file systems. * E.g., NFS does not consistently support exclusive locks. * <p> * <p> If locking is supported we guarantee exclusive access to the * storage directory. Otherwise, no guarantee is given. * * @throws IOException if locking fails */ private void lock(File dir) throws IOException { FileLock lock = tryLock(dir); if (lock == null) { String msg = "Cannot lock " + dir + ". The directory is already locked. " + channelNameDescriptor; LOGGER.info(msg); throw new IOException(msg); } FileLock secondLock = tryLock(dir); if (secondLock != null) { LOGGER.warn("Directory " + dir + " does not support locking"); secondLock.release(); secondLock.channel().close(); } locks.put(dir.getAbsolutePath(), lock); }
/** * Unlock storage. * * @throws IOException */ public void unlock() throws IOException { if (this.lock == null) return; this.lock.release(); lock.channel().close(); lock = null; }
void unlock() { if (directoryLock != null && directoryLock.isValid()) { try { directoryLock.release(); directoryLock.channel().close(); deleteFile(lockFile); } catch (IOException e) { throw new CacheException("Failed to release disk store path's lock file:" + lockFile, e); } } if (autoCreated) { if (diskStorePath.delete()) { LOG.debug("Deleted directory " + diskStorePath.getName()); } } }
try { lock.release(); lock.channel().close(); new File(directory, LOCK_FILE).delete(); } catch (IOException e) {
/** * Unlock storage. * * @throws IOException */ public void unlock() throws IOException { if (this.lock == null) return; this.lock.release(); lock.channel().close(); lock = null; }
protected FileChannel lockedFileChannel() { try { fileLockLock.lock(); return fileLock != null ? fileLock.channel() : null; } finally { fileLockLock.unlock(); } }
/** * Unlock storage. * * @throws IOException */ public void unlock() throws IOException { if (this.lock == null) return; this.lock.release(); lock.channel().close(); lock = null; }
/** * Unlock storage. * * @throws IOException */ public void unlock() throws IOException { if (this.lock == null) return; this.lock.release(); lock.channel().close(); lock = null; } }
protected FileChannel lockedFileChannel() { try { fileLockLock.lock(); return fileLock != null ? fileLock.channel() : null; } finally { fileLockLock.unlock(); } }
public void close() { close( lock.channel() ); lockFile.delete(); }
public synchronized void release() throws Exception { if (lock != null && lock.isValid()) { LOG.info("Releasing lock " + lockPath.getPath()); lock.release(); lock.channel().close(); } lock = null; }
private void releaseLock(FileLock lock) throws IOException { if (lock != null && lock.isValid()) { FileChannel lockChannel = lock.channel(); lock.release(); lockChannel.close(); } }
private static void unlock(File itemFile, boolean remove) throws IOException { if (!plugin.cfg.itemFsLock) return; FileLock fileLock = remove ? itemFileLocks.remove(itemFile.getCanonicalPath()) : itemFileLocks.get(itemFile.getCanonicalPath()); if (fileLock != null) { if (fileLock.isValid()) { fileLock.release(); } fileLock.channel().close(); } else { plugin.getLogger().warning("Lock for " + itemFile + " does not exist? If you are reloading a item, that's OK."); } }
public static void releaseLock(FileLock lock) { try { FileChannel channel = lock.channel(); lock.close(); channel.close(); } catch (IOException e) { log.d(e); } }
private byte[] getJarContent() throws IOException { ChannelInputStream channelInputStream = new ChannelInputStream(this.fileLock.channel()); final ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); final byte[] bytes = new byte[4096]; int bytesRead; while (((bytesRead = channelInputStream.read(bytes)) != -1)) { byteOutStream.write(bytes, 0, bytesRead); } channelInputStream.close(); return byteOutStream.toByteArray(); }
/** * @param channel * @param position * @param size * @param shared */ public SqlJetFileLock(SqlJetFileLockManager manager, FileLock fileLock) { super(fileLock.channel(), fileLock.position(), fileLock.size(), fileLock.isShared()); this.manager = manager; this.fileLock = fileLock; this.locksCount = 1; }