ru.tinkoff.kora.resilient.retry.Retry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resilient-kora Show documentation
Show all versions of resilient-kora Show documentation
Kora resilient-kora module
The newest version!
package ru.tinkoff.kora.resilient.retry;
import jakarta.annotation.Nonnull;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;
/**
* Retry executor implementation
*/
public interface Retry {
@FunctionalInterface
interface RetryRunnable {
void run() throws E;
}
@FunctionalInterface
interface RetrySupplier {
T get() throws E;
}
/**
* Retry State implementation for manual retry execution handling
*/
interface RetryState extends AutoCloseable {
enum RetryStatus {
ACCEPTED,
REJECTED,
EXHAUSTED
}
@Nonnull
RetryStatus onException(@Nonnull Throwable throwable);
int getAttempts();
int getAttemptsMax();
long getDelayNanos();
void doDelay();
@Override
void close();
}
/**
* @return new {@link RetryState}
*/
@Nonnull
RetryState asState();
/**
* @param runnable to execute for successful completion
* @throws RetryExhaustedException if exhausted all attempts
*/
void retry(@Nonnull RetryRunnable runnable) throws RetryExhaustedException, E;
/**
* @param supplier to use for value extraction
* @param type of value
* @return value is succeeded
* @throws RetryExhaustedException if exhausted all attempts
*/
T retry(@Nonnull RetrySupplier supplier) throws RetryExhaustedException, E;
/**
* @param supplier to use for value extraction
* @param fallback to use for value if failed to retrieve value from supplier
* @param type of value
* @return value is succeeded
*/
T retry(@Nonnull RetrySupplier supplier, RetrySupplier fallback) throws E;
/**
* @param supplier to use for value extraction
* @param type of value
* @return value is succeeded
*/
CompletionStage retry(@Nonnull Supplier> supplier);
}