@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(); }
@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(); } }
@Override public boolean next(LongPredicate consumer) { while (consumer.test(s.getAsLong())) { // go on } return true; } }
protected long finallyCloseLong(LongSupplier lp) { try { return lp.getAsLong(); } catch (Exception e) { LOGGER.error(e); throw e; } finally { close(); } }
/** * Updates generation using the {@link #generationSupplier}. If there has been a generation change * since construction of this seeker or since last calling this method the generation context in this * seeker is updated. * * @return {@code true} if generation was updated, which means that caller should retry its most recent read. */ private boolean generationCatchup() { long newGeneration = generationSupplier.getAsLong(); long newStableGeneration = Generation.stableGeneration( newGeneration ); long newUnstableGeneration = Generation.unstableGeneration( newGeneration ); if ( newStableGeneration != stableGeneration || newUnstableGeneration != unstableGeneration ) { stableGeneration = newStableGeneration; unstableGeneration = newUnstableGeneration; return true; } return false; }
@Test public void constructorShouldCallHighIdSupplierOnNonExistingIdFile() { // Given // An empty file (default, nothing to do) // and a mock supplier to test against LongSupplier highId = mock( LongSupplier.class ); when( highId.getAsLong() ).thenReturn( 0L ); // necessary, otherwise it runs into NPE in the constructor below // When // The id generator is started IdGeneratorImpl idGenerator = new IdGeneratorImpl( fsr.get(), file, 100, 100, false, IdType.NODE, highId ); // Then // The highId supplier must have been called to get the high id verify( highId ).getAsLong(); idGenerator.close(); }
ReadOnlyIdGenerator( LongSupplier highId, FileSystemAbstraction fs, File filename ) { if ( fs != null && fs.fileExists( filename ) ) { try { this.highId = IdGeneratorImpl.readHighId( fs, filename ); defragCount = IdGeneratorImpl.readDefragCount( fs, filename ); } catch ( IOException e ) { throw new UnderlyingStorageException( "Failed to read id counts of the id file: " + filename, e ); } } else { this.highId = highId.getAsLong(); defragCount = 0; } }
@Test public void invokeLongSuppliersShouldUpdateStats() { LongSupplier supplier1 = mock(LongSupplier.class); when(supplier1.getAsLong()).thenReturn(23L); stats.setLongSupplier(4, supplier1); assertEquals(0, stats.invokeSuppliers()); verify(supplier1).getAsLong(); assertEquals(23L, stats.getLong(4)); }