use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class VdcManager method enableIpsec.
private void enableIpsec() throws Exception {
InterProcessLock lock = null;
try {
lock = coordinator.getCoordinatorClient().getSiteLocalLock("ipseclock");
lock.acquire();
log.info("Acquired the lock {}", "ipseclock");
String preSharedKey = ipsecConfig.getPreSharedKeyFromZK();
if (StringUtil.isBlank(preSharedKey)) {
log.info("No pre shared key in zk, generate a new key");
ipsecMgr.rotateKey(true);
} else {
log.info("First ipsec key found in zk. No need to regenerate it");
}
} finally {
if (lock != null) {
lock.release();
}
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project nakadi by zalando.
the class TimelineSyncImpl method runLocked.
private void runLocked(final Runnable action) {
try {
Exception releaseException = null;
final InterProcessLock lock = new InterProcessSemaphoreMutex(zooKeeperHolder.get(), ROOT_PATH + "/lock");
lock.acquire();
try {
action.run();
} finally {
try {
lock.release();
} catch (final Exception ex) {
LOG.error("Failed to release lock", ex);
releaseException = ex;
}
}
if (null != releaseException) {
throw releaseException;
}
} catch (final RuntimeException ex) {
throw ex;
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class GarbageCollectionExecutorLoop method run.
@Override
public void run() {
InterProcessLock lock = null;
try {
lock = getLockForGC();
if (lock == null) {
log.info("Can't get GC lock, wait for next run.");
return;
}
} catch (Exception e) {
log.warn("Failed to acquire ZK lock for GC", e);
return;
}
long beginTime = System.currentTimeMillis();
log.info("Begin to GC...");
try {
if (!preGC()) {
// can't run GC now
return;
}
int maxLevels = dependencyTracker.getLevels();
for (int i = 0; i < maxLevels; i++) {
log.info("Now processing level {}", i);
List<Class<? extends DataObject>> list = new ArrayList(dependencyTracker.getTypesInLevel(i));
Collections.shuffle(list);
for (Class<? extends DataObject> clazz : list) {
if (canRunGCOnClass(clazz)) {
GarbageCollectionRunnable gc = genGCTask(clazz);
futures.add(executorPool.submit(gc));
}
}
waitTasksToComplete();
}
} finally {
try {
postGC();
} finally {
releaseLockForGC(lock);
log.info("GC is finished, consume time: {} seconds", (System.currentTimeMillis() - beginTime) / 1000);
}
}
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class DbServiceImpl method getLock.
private InterProcessLock getLock(String name) throws Exception {
InterProcessLock lock = null;
while (true) {
try {
lock = _coordinator.getSiteLocalLock(name);
lock.acquire();
// got lock
break;
} catch (Exception e) {
if (_coordinator.isConnected()) {
throw e;
}
}
}
return lock;
}
use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.
the class MigrationHandlerImpl method getLock.
private InterProcessLock getLock(String name) throws Exception {
InterProcessLock lock = null;
while (true) {
try {
lock = coordinator.getLock(name);
lock.acquire();
// got lock
break;
} catch (Exception e) {
if (coordinator.isConnected()) {
throw e;
}
}
}
return lock;
}
Aggregations