public static <U> CompletableFuture<U> withRetriesAsync(Supplier<CompletableFuture<U>> futureSupplier, Predicate<Throwable> predicate, int numOfTries, ScheduledExecutorService executor) { return Retry .withExpBackoff(100, 2, numOfTries, 10000) .retryWhen(predicate) .runAsync(futureSupplier, executor); }
public static <U> U withRetries(Supplier<U> supplier, Predicate<Throwable> predicate, int numOfTries) { return Retry.withExpBackoff(100, 2, numOfTries, 1000) .retryWhen(predicate) .run(supplier::get); }
/** * Writes the given 32-bit Integer to the given ArrayView at the given offset. * * @param target The ArrayView to write to. * @param offset The offset within the ArrayView to write at. * @param value The value to write. * @return The number of bytes written. */ public static int writeInt(ArrayView target, int offset, int value) { return writeInt(target.array(), target.arrayOffset() + offset, value); }
/** * Creates a new instance of the HashedArray class. * * @param array An {@link ArrayView} to wrap. */ public HashedArray(ArrayView array) { super(array.array(), array.arrayOffset(), array.getLength()); this.hashCode = hashCode(array); }
private CompletableFuture<Integer> retryFuture(final long delay, final int multiplier, final int attempts, final long maxDelay, final boolean success, final ScheduledExecutorService executorService) { loopCounter.set(0); accumulator.set(0); return Retry.withExpBackoff(delay, multiplier, attempts, maxDelay) .retryingOn(RetryableException.class) .throwingOn(NonretryableException.class) .runAsync(() -> futureComputation(success, executorService), executorService); }
private Retry.RetryAndThrowBase<? extends Exception> createRetryPolicy(int maxWriteAttempts, int writeTimeout) { int initialDelay = writeTimeout / maxWriteAttempts; int maxDelay = writeTimeout * maxWriteAttempts; return Retry.withExpBackoff(initialDelay, 2, maxWriteAttempts, maxDelay) .retryWhen(ex -> true); // Retry for every exception. }
private ByteArraySegment getFooter(long rootPageOffset, int rootPageLength) { byte[] result = new byte[FOOTER_LENGTH]; BitConverter.writeLong(result, 0, rootPageOffset); BitConverter.writeInt(result, Long.BYTES, rootPageLength); return new ByteArraySegment(result); }
/** * Writes the given 64-bit Long to the given ArrayView at the given offset. * * @param target The ArrayView to write to. * @param offset The offset within the ArrayView to write at. * @param value The value to write. * @return The number of bytes written. */ public static int writeLong(ArrayView target, int offset, long value) { return writeLong(target.array(), target.arrayOffset() + offset, value); }
/** * Writes the given 16-bit Short to the given ArrayView at the given offset. * * @param target The ArrayView to write to. * @param offset The offset within the ArrayView to write at. * @param value The value to write. * @return The number of bytes written. */ public static int writeShort(ArrayView target, int offset, short value) { return writeShort(target.array(), target.arrayOffset() + offset, value); }
/** * Creates a new instance of the RocksDBConfig class. * * @param properties The TypedProperties object to read Properties from. */ private RocksDBConfig(TypedProperties properties) throws ConfigurationException { this.databaseDir = properties.get(DATABASE_DIR); this.writeBufferSizeMB = properties.getInt(WRITE_BUFFER_SIZE_MB); this.readCacheSizeMB = properties.getInt(READ_CACHE_SIZE_MB); this.cacheBlockSizeKB = properties.getInt(CACHE_BLOCK_SIZE_KB); }
private ByteArraySegment serializeValue(Long value) { if (value == null || value == Attributes.NULL_ATTRIBUTE_VALUE) { // Deletion. return null; } byte[] result = new byte[VALUE_LENGTH]; BitConverter.writeLong(result, 0, value); return new ByteArraySegment(result); }
private ByteArraySegment serializeInt(int value) { byte[] r = new byte[Integer.BYTES]; BitConverter.writeInt(r, 0, value); return new ByteArraySegment(r); }
public static <U> CompletableFuture<U> withIndefiniteRetriesAsync(Supplier<CompletableFuture<U>> futureSupplier, Consumer<Throwable> exceptionConsumer, ScheduledExecutorService executor) { return Retry .indefinitelyWithExpBackoff(100, 2, 10000, exceptionConsumer) .runAsync(futureSupplier, executor); }
/** * Creates a new ConfigBuilder that can be used to create instances of this class. * * @return A new Builder for this class. */ public static ConfigBuilder<DurableLogConfig> builder() { return new ConfigBuilder<>(COMPONENT_CODE, DurableLogConfig::new); }
/** * Updates the Header of this BTreePage to reflect that it contains the given number of items. This does not perform * any resizing. * * @param itemCount The count to set. */ private void setCount(int itemCount) { BitConverter.writeInt(this.header, COUNT_OFFSET, itemCount); this.count = itemCount; }
/** * Gets this BTreePage's Id from its footer. */ private int getFooterId() { return BitConverter.readInt(this.footer, 0); }
@Override public boolean equals(Object obj) { if (obj instanceof HashedArray) { HashedArray ha = (HashedArray) obj; return this.hashCode == ha.hashCode && arrayEquals(this, ha); } return false; }
/** * Gets the value of a String property. * * @param property The Property to get. * @return The property value or default value, if no such is defined in the base Properties. * @throws ConfigurationException When the given property name does not exist within the current component and the property * does not have a default value set. */ public String get(Property<String> property) throws ConfigurationException { return tryGet(property, s -> s); }
private ByteArraySegment serializeLong(long value) { byte[] r = new byte[Long.BYTES]; BitConverter.writeLong(r, 0, value); return new ByteArraySegment(r); }