in curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/InterProcessMultiLock.java [79:119]
public boolean acquire(long time, TimeUnit unit) throws Exception {
Exception exception = null;
List<InterProcessLock> acquired = Lists.newArrayList();
boolean success = true;
for (InterProcessLock lock : locks) {
try {
if (unit == null) {
lock.acquire();
acquired.add(lock);
} else {
if (lock.acquire(time, unit)) {
acquired.add(lock);
} else {
success = false;
break;
}
}
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
success = false;
exception = e;
}
}
if (!success) {
for (InterProcessLock lock : reverse(acquired)) {
try {
lock.release();
} catch (Exception e) {
ThreadUtils.checkInterrupted(e);
// ignore
}
}
}
if (exception != null) {
throw exception;
}
return success;
}