Skip to content

Commit 6971872

Browse files
committed
All bulkheads should be fair
1 parent c342af0 commit 6971872

File tree

5 files changed

+5
-28
lines changed

5 files changed

+5
-28
lines changed

src/main/java/dev/failsafe/Bulkhead.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public interface Bulkhead<R> extends Policy<R> {
3535
/**
3636
* Returns a Bulkhead for the {@code maxConcurrency} that has {@link BulkheadBuilder#withMaxWaitTime(Duration) zero
37-
* wait} and is {@link BulkheadBuilder#withFairness() not fair} by default.
37+
* wait}.
3838
*
3939
* @param maxConcurrency controls the max concurrent executions that are permitted within the bulkhead
4040
*/
@@ -43,18 +43,16 @@ static <R> BulkheadBuilder<R> builder(int maxConcurrency) {
4343
}
4444

4545
/**
46-
* Creates a new BulkheadBuilder that will be based on the {@code config}. The built bulkhead is {@link
47-
* BulkheadBuilder#withFairness() not fair} by default.
46+
* Creates a new BulkheadBuilder that will be based on the {@code config}.
4847
*/
4948
static <R> BulkheadBuilder<R> builder(BulkheadConfig<R> config) {
5049
return new BulkheadBuilder<>(config);
5150
}
5251

5352
/**
5453
* Returns a Bulkhead for the {@code maxConcurrency} that has {@link BulkheadBuilder#withMaxWaitTime(Duration) zero
55-
* wait} and is {@link BulkheadBuilder#withFairness() not fair} by default. Alias for {@code
56-
* Bulkhead.builder(maxConcurrency).build()}. To configure additional options on a Bulkhead, use {@link #builder(int)}
57-
* instead.
54+
* wait}. Alias for {@code Bulkhead.builder(maxConcurrency).build()}. To configure additional options on a Bulkhead,
55+
* use {@link #builder(int)} instead.
5856
*
5957
* @param maxConcurrency controls the max concurrent executions that are permitted within the bulkhead
6058
* @see #builder(int)

src/main/java/dev/failsafe/BulkheadBuilder.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,4 @@ public BulkheadBuilder<R> withMaxWaitTime(Duration maxWaitTime) {
5757
config.maxWaitTime = Assert.notNull(maxWaitTime, "maxWaitTime");
5858
return this;
5959
}
60-
61-
/**
62-
* Configures the bulkhead to be fair in permitting waiting execution in order.
63-
*/
64-
public BulkheadBuilder<R> withFairness() {
65-
config.fair = true;
66-
return this;
67-
}
6860
}

src/main/java/dev/failsafe/BulkheadConfig.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
public class BulkheadConfig<R> extends PolicyConfig<R> {
2727
int maxConcurrency;
2828
Duration maxWaitTime;
29-
boolean fair;
3029

3130
BulkheadConfig(int maxConcurrency) {
3231
this.maxConcurrency = maxConcurrency;
@@ -37,7 +36,6 @@ public class BulkheadConfig<R> extends PolicyConfig<R> {
3736
super(config);
3837
maxConcurrency = config.maxConcurrency;
3938
maxWaitTime = config.maxWaitTime;
40-
fair = config.fair;
4139
}
4240

4341
/**
@@ -58,13 +56,4 @@ public int getMaxConcurrency() {
5856
public Duration getMaxWaitTime() {
5957
return maxWaitTime;
6058
}
61-
62-
/**
63-
* Returns whether the Bulkhead is fair in permitting waiting executions in order.
64-
*
65-
* @see BulkheadBuilder#withFairness()
66-
*/
67-
public boolean isFair() {
68-
return fair;
69-
}
7059
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class BulkheadImpl<R> implements Bulkhead<R> {
3636

3737
public BulkheadImpl(BulkheadConfig<R> config) {
3838
this.config = config;
39-
semaphore = new Semaphore(config.getMaxConcurrency(), config.isFair());
39+
semaphore = new Semaphore(config.getMaxConcurrency(), true);
4040
}
4141

4242
@Override

src/test/java/dev/failsafe/BulkheadBuilderTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ public class BulkheadBuilderTest {
2626
public void shouldCreateBuilderFromExistingConfig() {
2727
BulkheadConfig<Object> initialConfig = Bulkhead.builder(5)
2828
.withMaxWaitTime(Duration.ofSeconds(10))
29-
.withFairness()
3029
.onSuccess(e -> {
3130
}).config;
3231
BulkheadConfig<Object> newConfig = Bulkhead.builder(initialConfig).config;
3332
assertEquals(newConfig.maxConcurrency, 5);
3433
assertEquals(newConfig.maxWaitTime, Duration.ofSeconds(10));
35-
assertTrue(newConfig.fair);
3634
assertNotNull(newConfig.successListener);
3735
}
3836
}

0 commit comments

Comments
 (0)