@Override public void initRead() { long txId = lastClosedTxIdSupplier.getAsLong(); assert txId >= BASE_TX_ID; lastClosedTxId = txId; dirty = false; }
@Override public boolean shouldCheck() { long currentTime = clock.getAsLong(); if ( currentTime > lastCheckTime + interval ) { lastCheckTime = currentTime; return true; } return false; } }
TimeoutCheckStrategy( long interval, LongSupplier clock ) { this.interval = interval; this.lastCheckTime = clock.getAsLong(); this.clock = clock; }
long getLastCommittedTransactionId() { return lastCommittedTransactionIdSupplier.getAsLong(); }
long committingTransactionId() { return committingTransactionIdSupplier.getAsLong(); }
@Override protected long doNextDelayMillis(int numAttemptsSoFar) { return nextDelay.getAsLong(); }
private long getLimit() { return limitSupplier == null ? limit : limitSupplier.getAsLong(); }
private boolean rotationDelayExceeded() { return earliestRotationTimeRef.get() <= currentTimeSupplier.getAsLong(); }
public long orElseGet(LongSupplier other) { return this != emptyInstance ? value : other.getAsLong(); }
@Override public long waitFor(final long sequence, LongSupplier cursor, final Runnable barrier) throws InterruptedException { long availableSequence; while ((availableSequence = cursor.getAsLong()) < sequence) { barrier.run(); } return availableSequence; } }
private synchronized long maybeCompute(LongSupplier supplier) { if (!initialized) { value = requireNonNull(supplier.getAsLong()); initialized = true; } return value; }
@Override public long waitFor(final long sequence, LongSupplier cursor, final Runnable barrier) throws InterruptedException { long availableSequence; while ((availableSequence = cursor.getAsLong()) < sequence) { barrier.run(); Thread.sleep(1); } return availableSequence; } }
@Override public long waitFor(final long sequence, LongSupplier cursor, final Runnable barrier) throws InterruptedException { long availableSequence; int counter = retries; while ((availableSequence = cursor.getAsLong()) < sequence) { counter = applyWaitMethod(barrier, counter); } return availableSequence; }
@Override public long waitFor(final long sequence, LongSupplier cursor, final Runnable barrier) throws InterruptedException { long availableSequence; int counter = SPIN_TRIES; while ((availableSequence = cursor.getAsLong()) < sequence) { counter = applyWaitMethod(barrier, counter); } return availableSequence; }
<T> long finallyClose(LongSupplier lp) { try { return lp.getAsLong(); } finally { close(); } }
@SuppressWarnings("UnusedAssignment") //for availableSequence @Override public long waitFor(long sequence, LongSupplier cursorSequence, Runnable barrier) throws InterruptedException { long availableSequence; if ((availableSequence = cursorSequence.getAsLong()) < sequence) { lock.lock(); try { while ((availableSequence = cursorSequence.getAsLong()) < sequence) { barrier.run(); processorNotifyCondition.await(); } } finally { lock.unlock(); } } while ((availableSequence = cursorSequence.getAsLong()) < sequence) { barrier.run(); } return availableSequence; } }
@Override public boolean next(LongPredicate consumer) { while (consumer.test(s.getAsLong())) { // go on } return true; } }
if ((availableSequence = cursorSequence.getAsLong()) < sequence) if ((availableSequence = cursorSequence.getAsLong()) >= sequence) processorNotifyCondition.await(); while ((availableSequence = cursorSequence.getAsLong()) < sequence); while ((availableSequence = cursorSequence.getAsLong()) < sequence)
/** * This method will return the value for the specified key if it is cached, * and if not, will calculate the value using the supplied method. The * computed value may or may not be stored in the cache afterwards. This * method is guaranteed to be lock-free, and might calculate the value * instead of using the cached one to avoid blocking. * * @param key the key to retrieve the value for * @param compute method to use to compute the value if it is not cached * @return the cached or computed value */ public long getOrCompute(K key, LongSupplier compute) { if (free.compareAndSet(true, false)) { try { return cache.computeIfAbsent(key, k -> compute.getAsLong()); } finally { free.set(true); } } else { return compute.getAsLong(); } }
/** * Writes all doc values updates to disk if there are any. * @return <code>true</code> iff any files where written */ boolean writeAllDocValuesUpdates() throws IOException { Collection<ReadersAndUpdates> copy; synchronized (this) { // this needs to be protected by the reader pool lock otherwise we hit ConcurrentModificationException copy = new HashSet<>(readerMap.values()); } boolean any = false; for (ReadersAndUpdates rld : copy) { any |= rld.writeFieldUpdates(directory, fieldNumbers, completedDelGenSupplier.getAsLong(), infoStream); } return any; }