Skip to content

Commit 13b3530

Browse files
committed
Make acquirePermit a default method on CircuitBreaker
1 parent 51519c2 commit 13b3530

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ enum State {
110110
* @see #recordSuccess()
111111
* @see #recordFailure()
112112
*/
113-
void acquirePermit();
113+
default void acquirePermit() {
114+
if (!tryAcquirePermit())
115+
throw new CircuitBreakerOpenException(this);
116+
}
114117

115118
/**
116119
* Attempts to acquire a permit to use the circuit breaker and returns whether a permit was acquired. Permission will

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public boolean tryAcquirePermit() {
5454
return state.get().tryAcquirePermit();
5555
}
5656

57-
@Override
58-
public void acquirePermit() {
59-
state.get().acquirePermit();
60-
}
61-
6257
@Override
6358
public void close() {
6459
transitionTo(State.CLOSED, config.getCloseListener(), null);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ public void handleConfigChange() {
6767
void checkThreshold(ExecutionContext<R> context) {
6868
}
6969

70-
void acquirePermit() {
71-
if (!tryAcquirePermit())
72-
throw new CircuitBreakerOpenException(breaker);
73-
}
74-
7570
abstract boolean tryAcquirePermit();
7671

7772
void releasePermit() {

0 commit comments

Comments
 (0)