Skip to content

Update checkstyle #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.gradle
.idea
build
.DS_Store
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/github/pepperkit/retry/BackoffFunction.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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");
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/github/pepperkit/retry/CallableRetry.java
Original file line number Diff line number Diff line change
@@ -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 <V> the type of returned value
*/
public interface CallableRetry<V> {

/**
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/pepperkit/retry/Retry.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/github/pepperkit/retry/RunnableRetry.java
Original file line number Diff line number Diff line change
@@ -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 {

/**
Expand Down