/** * {@inheritDoc} */ @Override public void close() throws IOException { //FileChannel.close closes the nioFileLock. Closing //it explicitly, else findbugs rule URF_UNREAD_FIELD is violated nioFileLock.close(); fileChannel.close(); }
final String current = file.readLine(); if (current != null && !current.equals(magic)) { lock.close(); lock = null; LOGGER.debug("Another process obtained a lock first ({})", Thread.currentThread().getName());
boolean result = true; try { fileLock.close(); fileLock = null; isLocked.set(false);
@Override public void close() throws IOException { if (mLock != null) { mLock.close(); } if (mRaf != null) { mRaf.close(); } } }
public static void unlock() { try { if (serverLockFile != null) { serverLockFile.close(); serverLockFile = null; } if (serverLockLock != null) { serverLockLock.close(); serverLockLock = null; } } catch (Exception ignored) { } }
@Override public void close() throws IOException { if (null != this.lock) { this.lock.close(); } this.file.close(); } }
@Override public void close() throws IOException { if (mLock != null) { mLock.close(); } if (mRaf != null) { mRaf.close(); } } }
/** * {@inheritDoc} */ @Override public void close() throws IOException { //FileChannel.close closes the nioFileLock. Closing //it explicitly, else findbugs rule URF_UNREAD_FIELD is violated nioFileLock.close(); fileChannel.close(); }
@Override public void close() throws IOException { if (mLock != null) { mLock.close(); } if (mRaf != null) { mRaf.close(); } } }
public static void unlock() { try { if (serverLockFile != null) { serverLockFile.close(); serverLockFile = null; } if (serverLockLock != null) { serverLockLock.close(); serverLockLock = null; } } catch (Exception ignored) { } }
@Override public void close() throws IOException { if (null != this.lock) { this.lock.close(); } this.file.close(); } }
public synchronized void release() { if (lock != null) { try { lock.close(); } catch (Exception e) { // ignore } lock = null; } if (lockFile != null) { try { lockFile.close(); } catch (Exception e) { // ignore } lockFile = null; } } }
@Override public void deleteOldFiles() throws IOException { for (String fileToDelete : filesToDelete) { final Path pathToDelete = targetDirectoryPath.resolve(fileToDelete); if (Files.exists(pathToDelete)) { try (final FileChannel fileChannel = FileChannel.open(pathToDelete, StandardOpenOption.WRITE, StandardOpenOption.DELETE_ON_CLOSE)) { fileChannel.lock().close(); } catch (FileNotFoundException e) { //That's ok } if (Files.exists(pathToDelete)) throw new IOException("Can't delete the file: " + pathToDelete); } } } }
synchronized void unlock() { FileChannel osFile = _osFile; _osFile = null; FileLock lock = _lock; _lock = null; if (lock != null) { try { lock.close(); } catch (Exception e) { log.log(Level.FINEST, e.toString(), e); } } if (osFile != null) { try { osFile.close(); } catch (Exception e) { log.log(Level.FINEST, e.toString(), e); } } }
synchronized boolean isFree() { if (_lock != null) { return false; } if (! Files.isReadable(_path)) { return true; } try (FileOutputStream fOs = (FileOutputStream) Files.newOutputStream(_path)) { FileLock lock = fOs.getChannel().tryLock(); if (lock != null) { lock.close(); return true; } else { return false; } } catch (Exception e) { log.finer(_path + ": isFree " + e); log.log(Level.FINEST, e.toString(), e); return true; } } }
public static void releaseLock(FileLock lock) { try { FileChannel channel = lock.channel(); lock.close(); channel.close(); } catch (IOException e) { log.d(e); } }
return () -> { finalLock.close(); finalChannel.close(); finalFile.close();
public void instanceCheck() { final List<ShutdownTask> shutdownRunnables = new ArrayList(); shutdownRunnables.add(() -> Files.deleteIfExists(lockFile)); try { Files.createDirectories(lockFile.getParent()); final RandomAccessFile randomAccessFileForLock = new RandomAccessFile(lockFile.toFile(), "rw"); shutdownRunnables.add(() -> randomAccessFileForLock.close()); final FileLock fileLock = randomAccessFileForLock.getChannel().tryLock(); if(fileLock == null) { throw new IllegalStateException("Another application is already running!"); } shutdownRunnables.add(() -> fileLock.close()); } catch (Exception e) { throw new RuntimeException("Instance checker went wrong!", e); } finally { final Thread shutdownHookThread = new Thread(() -> { shutdownRunnables.stream() .collect(Collectors.toCollection(LinkedList::new)) .descendingIterator() .forEachRemaining(task -> { try { task.run(); } catch (Exception e) { e.printStackTrace(); } }); }); Runtime.getRuntime().addShutdownHook(shutdownHookThread); } }}
@Override public void close() throws IOException { mMetadataLatch.acquireExclusive(); try { acquireExclusive(); try { if (mClosed) { return; } mClosed = true; mMetadataLock.close(); mMetadataFile.close(); Utils.delete(mMetadataBuffer); for (Object key : mTermLogs) { ((TermLog) key).close(); } } finally { releaseExclusive(); } } finally { mMetadataLatch.releaseExclusive(); } mWorker.join(true); } }
dbLock.close();