@Override public <R> Optional<R> execute(Supplier<R> executeTask) { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { return Optional.of(executeTask.get()); } finally { this.lock.unlock(stamp); } } return Optional.empty(); }
@Override public void execute(Runnable executeTask) { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { executeTask.run(); } finally { this.lock.unlock(stamp); } } }
@Override public <R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { return Optional.of(executeTask.get()); } finally { this.lock.unlock(stamp); } } return Optional.empty(); }
@Override public <E extends Exception> void execute(ExceptionRunnable<E> executeTask) throws E { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { executeTask.run(); } finally { this.lock.unlock(stamp); } } }
@Override public <R> Optional<R> execute(Supplier<R> executeTask) { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { return Optional.of(executeTask.get()); } finally { this.lock.unlock(stamp); } } return Optional.empty(); }
@Override public void execute(Runnable executeTask) { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { executeTask.run(); } finally { this.lock.unlock(stamp); } } }
@Override public <R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { return Optional.of(executeTask.get()); } finally { this.lock.unlock(stamp); } } return Optional.empty(); }
@Override public LockHandle acquireReadLockForKey(Bytes key) { StampedLock lock = makeLockForKey(key); try { long tryReadLock = lock.tryReadLock(readLockTimeout, TimeUnit.SECONDS); if (tryReadLock == 0) { throw new RuntimeException("timedout trying to read lock"); } return new LockHandle(tryReadLock, key, false); } catch (InterruptedException err) { Thread.currentThread().interrupt(); throw new RuntimeException(err); } }
/** * {@inheritDoc} * * If background thread is started then executes task in this thread, otherwise executes task in current thread. * * @param task */ @Override public void execute(Runnable task) { long stamp = stampedLock.tryReadLock(); if (stamp == 0) { task.run(); return; } try { taskQueue.add(task); LockSupport.unpark(workerThread); } finally { stampedLock.unlockRead(stamp); } }
/** * {@inheritDoc} * * If background thread is started then executes task in this thread, otherwise executes task in current thread. * * @param task */ @Override public void execute(Runnable task) { long stamp = stampedLock.tryReadLock(); if (stamp == 0) { task.run(); return; } try { taskQueue.add(task); LockSupport.unpark(workerThread); } finally { stampedLock.unlockRead(stamp); } }
@Override public LockHandle acquireReadLockForKey(Bytes key) { LockInstance lock = makeLockForKey(key); try { long tryReadLock = lock.lock.tryReadLock(readLockTimeout, TimeUnit.SECONDS); if (tryReadLock == 0) { throw new RuntimeException("timedout trying to read lock"); } return new LockHandle(tryReadLock, key, false, lock); } catch (InterruptedException err) { Thread.currentThread().interrupt(); throw new RuntimeException(err); } }
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException { long timeoutTime = System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(timeout, unit); long stamp = lock.tryReadLock(timeout, unit); if (!lock.validate(stamp)) { if (System.currentTimeMillis() > timeoutTime) throw new TimeoutException(); if (isCancelled()) throw new InterruptedException(); } try { return backing.get(); } catch (Exception e) { Discord4J.LOGGER.error(LogMarkers.UTIL, "Exception caught attempting to handle a ratelimited request", e); } finally { lock.unlockRead(stamp); } return null; }
private Consumer<HttpServerExchange> getSessionCloseTask() { StampedLock lock = this.lifecycleLock; long stamp = lock.tryReadLock(); if (stamp == 0L) { throw UndertowClusteringLogger.ROOT_LOGGER.sessionManagerStopped(); } AttachmentKey<io.undertow.server.session.Session> key = this.key; AtomicLong stampRef = new AtomicLong(stamp); return new Consumer<HttpServerExchange>() { @Override public void accept(HttpServerExchange exchange) { try { // Ensure we only unlock once. long stamp = stampRef.getAndSet(0L); if (stamp != 0L) { lock.unlock(stamp); } } finally { if (exchange != null) { exchange.removeAttachment(key); } } } }; }
@Override public <E extends Exception> void execute(ExceptionRunnable<E> executeTask) throws E { long stamp = this.lock.tryReadLock(); if (stamp != 0L) { try { executeTask.run(); } finally { this.lock.unlock(stamp); } } }
long stamp = mqttClientLock.tryReadLock(); if (stamp == 0l) { throw new JoynrDelayMessageException("Mqtt client not available (not connected)");