diff --git a/.gitignore b/.gitignore index bffa164..be04972 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .gradle .idea +build +.DS_Store diff --git a/LICENSE b/LICENSE index a9d48b9..3b45d71 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Artur Aukhatov +Copyright (c) 2022 PepperKit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b9f4bd0..bdde4ab 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ new BackoffFunction.Exponential(3); ``` #### Fixed -This is an elementary implementation, just return a constant value. +This is an elementary implementation, it just returns a constant value. ```text 3s -> 3s -> 3s -> 3s ``` diff --git a/build.gradle b/build.gradle index 3b80e2b..8febba0 100644 --- a/build.gradle +++ b/build.gradle @@ -51,9 +51,9 @@ test { } checkstyle { - toolVersion '8.42' + toolVersion '9.2.1' config project.resources.text - .fromUri(new URI("https://raw.githubusercontent.com/pepperkit/checkstyle/v1.0.0-8.45/checkstyle.xml")) + .fromUri(new URI("https://raw.githubusercontent.com/pepperkit/checkstyle/v1.0.2-9.2/checkstyle.xml")) } tasks.withType(Javadoc) { diff --git a/src/main/java/io/github/pepperkit/retry/BackoffFunction.java b/src/main/java/io/github/pepperkit/retry/BackoffFunction.java index f6d8408..c4ff28c 100644 --- a/src/main/java/io/github/pepperkit/retry/BackoffFunction.java +++ b/src/main/java/io/github/pepperkit/retry/BackoffFunction.java @@ -1,13 +1,25 @@ +/* + * Copyright (C) 2022 PepperKit + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ package io.github.pepperkit.retry; import java.security.SecureRandom; import java.time.Duration; +/** + * The backoff function determines how much to wait between the retries. + */ @FunctionalInterface public interface BackoffFunction { Duration delay(int attempt, Duration delay); + /** + * An elementary implementation of a backoff function, just returns a constant value. + */ class Fixed implements BackoffFunction { public Fixed() { @@ -20,11 +32,15 @@ public Duration delay(int attempt, Duration delay) { } } + /** + * Exponential backoff function waits progressively longer intervals between subsequent retries. + */ class Exponential implements BackoffFunction { private static final int DEFAULT_FACTOR = 3; private final int factor; + public Exponential(int factor) { if (factor < 1) { throw new IllegalArgumentException("Factor must be greater than 1"); @@ -45,6 +61,9 @@ public Duration delay(int attempt, Duration delay) { } } + /** + * Randomized backoff algorithm implementation, each interval value is determined randomly. + */ class Randomized implements BackoffFunction { private final int bound; diff --git a/src/main/java/io/github/pepperkit/retry/CallableRetry.java b/src/main/java/io/github/pepperkit/retry/CallableRetry.java index d3ae873..4b52d40 100644 --- a/src/main/java/io/github/pepperkit/retry/CallableRetry.java +++ b/src/main/java/io/github/pepperkit/retry/CallableRetry.java @@ -1,5 +1,15 @@ +/* + * Copyright (C) 2022 PepperKit + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ package io.github.pepperkit.retry; +/** + * Callable version of a retry action. + * @param the type of returned value + */ public interface CallableRetry { /** diff --git a/src/main/java/io/github/pepperkit/retry/Retry.java b/src/main/java/io/github/pepperkit/retry/Retry.java index 0e4735a..22f0131 100644 --- a/src/main/java/io/github/pepperkit/retry/Retry.java +++ b/src/main/java/io/github/pepperkit/retry/Retry.java @@ -1,3 +1,9 @@ +/* + * Copyright (C) 2022 PepperKit + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ package io.github.pepperkit.retry; import java.time.Duration; @@ -8,6 +14,9 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +/** + * A static interface for the Retry library. + */ public final class Retry { private static final int DEFAULT_MAX_ATTEMPTS = 3; diff --git a/src/main/java/io/github/pepperkit/retry/RetryInterruptedException.java b/src/main/java/io/github/pepperkit/retry/RetryInterruptedException.java index 1597667..268a8e1 100644 --- a/src/main/java/io/github/pepperkit/retry/RetryInterruptedException.java +++ b/src/main/java/io/github/pepperkit/retry/RetryInterruptedException.java @@ -1,5 +1,14 @@ +/* + * Copyright (C) 2022 PepperKit + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ package io.github.pepperkit.retry; +/** + * Exception, which occurs if retry attempt was interrupted. + */ public class RetryInterruptedException extends RuntimeException { private static final long serialVersionUID = 5443040601324416580L; diff --git a/src/main/java/io/github/pepperkit/retry/RunnableRetry.java b/src/main/java/io/github/pepperkit/retry/RunnableRetry.java index ea5c9c2..c5680d8 100644 --- a/src/main/java/io/github/pepperkit/retry/RunnableRetry.java +++ b/src/main/java/io/github/pepperkit/retry/RunnableRetry.java @@ -1,5 +1,14 @@ +/* + * Copyright (C) 2022 PepperKit + * + * This software may be modified and distributed under the terms + * of the MIT license. See the LICENSE file for details. + */ package io.github.pepperkit.retry; +/** + * Runnable version of a retry action. + */ public interface RunnableRetry { /**