}
}
public void close() {
CompositeStoppable stoppable = new CompositeStoppable();
stoppable.add(new Stoppable() {
public void stop() {
try {
fileLockContentionHandler.stop(lockId);
} catch (Exception e) {
throw new RuntimeException("Unable to stop listening for file lock requests for " + displayName, e);
}
}
});
stoppable.add(new Stoppable() {
public void stop() {
if (lockFileAccess == null) {
return;
}
try {
LOGGER.debug("Releasing lock on {}.", displayName);
try {
if (lock != null && !lock.isShared()) {
// Discard information region
java.nio.channels.FileLock info;
try {
info = lockInformationRegion(LockMode.Exclusive, System.currentTimeMillis() + shortTimeoutMs);
} catch (InterruptedException e) {
throw throwAsUncheckedException(e);
}
if (info != null) {
try {
lockFileAccess.clearLockInfo();
} finally {
info.release();
}
}
}
} finally {
lockFileAccess.close();
}
} catch (Exception e) {
throw new RuntimeException("Failed to release lock on " + displayName, e);
}
}
});
stoppable.add(new Stoppable() {
public void stop() {
lock = null;
lockFileAccess = null;
lockedFiles.remove(target);
}