@Override public LockHandle acquireWriteLockForKey(Bytes key) { LockInstance lock = makeLockForKey(key); try { long tryWriteLock = lock.lock.tryWriteLock(writeLockTimeout, TimeUnit.SECONDS); if (tryWriteLock == 0) { throw new RuntimeException("timed out acquiring lock for write"); } return new LockHandle(tryWriteLock, key, true, lock); } catch (InterruptedException err) { Thread.currentThread().interrupt(); throw new RuntimeException(err); } }
@Override public LockHandle acquireWriteLockForKey(Bytes key) { StampedLock lock = makeLockForKey(key); try { long tryWriteLock = lock.tryWriteLock(writeLockTimeout, TimeUnit.SECONDS); if (tryWriteLock == 0) { throw new RuntimeException("timed out acquiring lock for write"); } return new LockHandle(tryWriteLock, key, true); } catch (InterruptedException err) { Thread.currentThread().interrupt(); throw new RuntimeException(err); } }
public SetMultimap<Integer, FileReference> getWithShortCircuit() throws InterruptedException { SetMultimap<Integer, FileReference> fileRefMap = HashMultimap.create(); long end = System.nanoTime() + MAX_WAIT_NANOS; long remaining = MAX_WAIT_NANOS; while (true) { if (semaphore.tryWriteLock(remaining, TimeUnit.NANOSECONDS) == 0) { lateFileRefFinds = ConcurrentHashMultiset.create(); shortCircuited = true; log.warn("Timed out waiting for mesh file list: {}. After waiting {}", this, MAX_WAIT_NANOS); return fileRefMap; } FileReference fileReference = references.poll(); while (fileReference != null) { if (fileReference == END_SIGNAL) { log.debug("Finished collecting file refs for: {}", this); return fileRefMap; } fileRefMap.put(getTaskId(fileReference), fileReference); fileReference = references.poll(); } remaining = end - System.nanoTime(); } }
@Override public synchronized void stop() { if (!this.lifecycleStamp.isPresent()) { try { long stamp = this.lifecycleLock.tryWriteLock(this.manager.getDefaultMaxInactiveInterval().getSeconds(), TimeUnit.SECONDS); if (stamp != 0) { this.lifecycleStamp = OptionalLong.of(stamp); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } this.manager.stop(); } }
if (stampedLock.tryWriteLock() == 0) { return false;
final long lastTime = System.nanoTime(); if (stampedLock.tryWriteLock(nanosTimeout, TimeUnit.NANOSECONDS) == 0) { return false;
if (message == null) { int stamp = lock.tryWriteLock(); try { if (stamp != 0) {