Skip to content

Commit a1d0f6e

Browse files
committed
Misc tiny improvements
- Guard against nanoseconds overflowing a long in RateLimiter - Clarify javadocs
1 parent 3560969 commit a1d0f6e

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/main/java/dev/failsafe/CircuitBreaker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ static <R> CircuitBreakerBuilder<R> builder(CircuitBreakerConfig<R> config) {
7777
/**
7878
* Creates a count based CircuitBreaker that opens after a {@link CircuitBreakerBuilder#withFailureThreshold(int)
7979
* single failure}, closes after a {@link CircuitBreakerBuilder#withSuccessThreshold(int) single success}, and has a 1
80-
* minute {@link CircuitBreakerBuilder#withDelay(Duration) delay} by default.
80+
* minute {@link CircuitBreakerBuilder#withDelay(Duration) delay} by default. To configure additional options on a
81+
* CircuitBreaker, use {@link #builder()} instead.
8182
*
8283
* @see #builder()
8384
*/
@@ -121,8 +122,8 @@ default void acquirePermit() {
121122
}
122123

123124
/**
124-
* Tries to acquire a permit to use the circuit breaker and returns whether a permit was acquired. Permission will
125-
* be automatically released when a result or failure is recorded.
125+
* Tries to acquire a permit to use the circuit breaker and returns whether a permit was acquired. Permission will be
126+
* automatically released when a result or failure is recorded.
126127
*
127128
* @see #recordResult(Object)
128129
* @see #recordFailure(Throwable)

src/main/java/dev/failsafe/CircuitBreakerOpenException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package dev.failsafe;
1717

1818
/**
19-
* Thrown when an execution is attempted while a configured {@link CircuitBreaker} is open.
19+
* Thrown when an execution is attempted against a {@link CircuitBreaker} that is open.
2020
*
2121
* @author Jonathan Halterman
2222
*/

src/main/java/dev/failsafe/RetryPolicy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ static <R> RetryPolicyBuilder<R> builder(RetryPolicyConfig<R> config) {
4545
}
4646

4747
/**
48-
* Creates a RetryPolicy that allows 3 execution attempts max with no delay.
48+
* Creates a RetryPolicy that allows 3 execution attempts max with no delay. To configure additional options on a
49+
* RetryPolicy, use {@link #builder()} instead.
4950
*
50-
* @see #builder()
51+
* @see #builder()
5152
*/
5253
static <R> RetryPolicy<R> ofDefaults() {
5354
return RetryPolicy.<R>builder().build();

src/main/java/dev/failsafe/Timeout.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ static <R> TimeoutBuilder<R> builder(TimeoutConfig<R> config) {
7070

7171
/**
7272
* Returns a {@link Timeout} that fails an execution with {@link TimeoutExceededException TimeoutExceededException} if
73-
* it exceeds the {@code timeout}. Alias for {@code Timeout.builder(timeout).build()}. To configure other options on a
74-
* Timeout, use {@link #builder(Duration)} instead.
73+
* it exceeds the {@code timeout}. Alias for {@code Timeout.builder(timeout).build()}. To configure additional options
74+
* on a Timeout, use {@link #builder(Duration)} instead.
7575
*
7676
* @param timeout the duration after which an execution is failed with {@link TimeoutExceededException
7777
* TimeoutExceededException}.
7878
* @param <R> result type
7979
* @throws NullPointerException If {@code timeout} is null
8080
* @throws IllegalArgumentException If {@code timeout} is <= 0
81+
*
82+
* @see #builder(Duration)
8183
*/
8284
static <R> Timeout<R> of(Duration timeout) {
8385
return new TimeoutImpl<>(new TimeoutConfig<>(timeout, false));

src/main/java/dev/failsafe/internal/RateLimiterImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import dev.failsafe.RateLimiterConfig;
2020
import dev.failsafe.internal.RateLimiterStats.Stopwatch;
2121
import dev.failsafe.internal.util.Assert;
22+
import dev.failsafe.internal.util.Durations;
2223
import dev.failsafe.spi.PolicyExecutor;
2324

2425
import java.time.Duration;
@@ -68,7 +69,7 @@ public boolean tryAcquirePermits(int permits) {
6869
public boolean tryAcquirePermits(int permits, Duration maxWaitTime) throws InterruptedException {
6970
Assert.isTrue(permits > 0, "permits must be > 0");
7071
Assert.notNull(maxWaitTime, "maxWaitTime");
71-
long waitNanos = stats.acquirePermits(permits, maxWaitTime);
72+
long waitNanos = stats.acquirePermits(permits, Durations.ofSafeNanos(maxWaitTime));
7273
if (waitNanos == -1)
7374
return false;
7475
if (waitNanos > 0)

0 commit comments

Comments
 (0)