public synchronized boolean tryLock(LockWatcher lw, byte data[]) throws KeeperException, InterruptedException { TryLockAsyncLockWatcher tlalw = new TryLockAsyncLockWatcher(lw); lockAsync(tlalw, data); if (tlalw.acquiredLock) { return true; } if (asyncLock != null) { zooKeeper.recursiveDelete(path + "/" + asyncLock, NodeMissingPolicy.SKIP); asyncLock = null; } return false; }
lockAsync(myLock, lw);
lockAsync(asyncLock, lw);
private void getMasterLock(final String zMasterLoc) throws KeeperException, InterruptedException { log.info("trying to get master lock"); final String masterClientAddress = hostname + ":" + getConfiguration().getPort(Property.MASTER_CLIENTPORT)[0]; while (true) { MasterLockWatcher masterLockWatcher = new MasterLockWatcher(); masterLock = new ZooLock(getContext().getZooReaderWriter(), zMasterLoc); masterLock.lockAsync(masterLockWatcher, masterClientAddress.getBytes()); masterLockWatcher.waitForChange(); if (masterLockWatcher.acquiredLock) { break; } if (!masterLockWatcher.failedToAcquireLock) { throw new IllegalStateException("master lock in unknown state"); } masterLock.tryToCancelAsyncLockOrUnlock(); sleepUninterruptibly(TIME_TO_WAIT_BETWEEN_LOCK_CHECKS, TimeUnit.MILLISECONDS); } setMasterState(MasterState.HAVE_LOCK); }
MoniterLockWatcher monitorLockWatcher = new MoniterLockWatcher(); monitorLock = new ZooLock(zoo, monitorLockPath); monitorLock.lockAsync(monitorLockWatcher, new byte[0]);
public synchronized boolean tryLock(LockWatcher lw, byte data[]) throws KeeperException, InterruptedException { TryLockAsyncLockWatcher tlalw = new TryLockAsyncLockWatcher(lw); lockAsync(tlalw, data); if (tlalw.acquiredLock) { return true; } if (asyncLock != null) { zooKeeper.recursiveDelete(path + "/" + asyncLock, NodeMissingPolicy.SKIP); asyncLock = null; } return false; }
lockAsync(myLock, lw);
lockAsync(asyncLock, lw);