@Test public void tracksTimestampsInOrder() { AsyncLock lock2 = tracker.getLockFor(TIMESTAMP_2); lock2.lock(REQUEST_1); AsyncLock lock1 = tracker.getLockFor(TIMESTAMP_1); lock1.lock(REQUEST_2); assertThat(tracker.getImmutableTimestamp().get()).isEqualTo(TIMESTAMP_1); lock1.unlock(REQUEST_2); assertThat(tracker.getImmutableTimestamp().get()).isEqualTo(TIMESTAMP_2); }
private void timeoutAll() { for (AsyncLock lock : locks.get()) { lock.timeout(requestId); } } }
public AsyncResult<Void> waitForLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.waitUntilAvailable(requestId)) .execute(); }
public synchronized boolean unlock() { if (isUnlocked) { return false; } isUnlocked = true; for (AsyncLock lock : acquiredLocks) { lock.unlock(token.getRequestId()); } return true; }
private AsyncResult<Void> lock(long timestamp, UUID requestId) { return tracker.getLockFor(timestamp).lock(requestId); }
private void unlockAll() { try { for (AsyncLock lock : locks.get()) { lock.unlock(requestId); } } catch (Throwable t) { log.error("Error while unlocking locks", SafeArg.of("requestId", requestId), t); } }
public AsyncResult<HeldLocks> acquireLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.lock(requestId)).execute() .map(ignored -> new HeldLocks(lockLog, locks.get(), requestId)); }
private void unlock(long timestamp, UUID requestId) { tracker.getLockFor(timestamp).unlock(requestId); }
public AsyncResult<HeldLocks> acquireLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.lock(requestId)).execute() .map(ignored -> new HeldLocks(lockLog, locks.get(), requestId)); }
private void timeoutAll() { for (AsyncLock lock : locks.get()) { lock.timeout(requestId); } } }
public AsyncResult<Void> waitForLocks(UUID requestId, OrderedLocks locks, TimeLimit timeout) { return new Acquisition(requestId, locks, timeout, lock -> lock.waitUntilAvailable(requestId)) .execute(); }
public synchronized boolean unlock() { if (isUnlocked) { return false; } isUnlocked = true; for (AsyncLock lock : acquiredLocks) { lock.unlock(token.getRequestId()); } return true; }
private void unlockAll() { try { for (AsyncLock lock : locks.get()) { lock.unlock(requestId); } } catch (Throwable t) { log.error("Error while unlocking locks", SafeArg.of("requestId", requestId), t); } }