@Override public synchronized void close() { if (closed) { return; } try { fileLock.release(); } catch (IOException e) { // nothing to do here -- it was already released or there are underlying errors we cannot recover from logger.debug("Failed to release the lock {}", fileLock, e); } finally { closed = true; try { lockChannel.close(); } catch (IOException e) { // nothing to do here -- underlying errors but recovery not possible here or in client, and already closed logger.debug("Failed to close lockChannel {}", lockChannel, e); } } try { super.close(); } catch (IOException e) { // should never happen } }
@Override public synchronized void close() { if (closed) { return; } try { fileLock.release(); } catch (IOException e) { // nothing to do here -- it was already released or there are underlying errors we cannot recover from logger.debug("Failed to release the lock {}", fileLock, e); } finally { closed = true; try { lockChannel.close(); } catch (IOException e) { // nothing to do here -- underlying errors but recovery not possible here or in client, and already closed logger.debug("Failed to close lockChannel {}", lockChannel, e); } } try { super.close(); } catch (IOException e) { // should never happen } }
/** * Closes this stream and releases any system resources associated * with it. If the stream is already closed then invoking this * method has no effect. * * @throws java.io.IOException if an I/O error occurs */ @Override public void close() throws IOException { Integer waitTime = 100; while (true) { if (zkLock.isAcquiredInThisProcess()) { try { logger.info("ZooKeeperRepository's close() called while lock is acquired. " + "Waiting " + waitTime + " ms before trying again."); wait(waitTime); } catch (InterruptedException e) { logger.warn("Interrupted while waiting", e); } } else { // TODO: Make sure the race condition between the if condition and the close is harmless... zkClient.close(); break; } } closed = true; super.close(); }