forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 773: Aded support to rate limiter configuration customization (R…
- Loading branch information
Showing
30 changed files
with
287 additions
and
118 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...e4j-framework-common/src/main/java/io/github/resilience4j/common/CompositeCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.resilience4j.common; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* the composite of any spring resilience4j type config customizer implementations. | ||
*/ | ||
public class CompositeCustomizer<T extends CustomizerWithName> { | ||
|
||
private final Map<String, T> customizerMap = new HashMap<>(); | ||
|
||
public CompositeCustomizer(List<T> customizers) { | ||
if (customizers != null && !customizers.isEmpty()) { | ||
customizerMap.putAll(customizers.stream() | ||
.collect( | ||
Collectors.toMap(CustomizerWithName::name, Function.identity()))); | ||
} | ||
} | ||
|
||
/** | ||
* @param instanceName the resilience4j instance name | ||
* @return the found spring customizer if any . | ||
*/ | ||
public Optional<T> getCustomizer(String instanceName) { | ||
return Optional.ofNullable(customizerMap.get(instanceName)); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ce4j-framework-common/src/main/java/io/github/resilience4j/common/CustomizerWithName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.resilience4j.common; | ||
|
||
/** | ||
* common interface for different spring config customizers implementation | ||
*/ | ||
public interface CustomizerWithName { | ||
|
||
/** | ||
* @return name of the resilience4j type instance to be customized | ||
*/ | ||
String name(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...b/resilience4j/common/circuitbreaker/configuration/CompositeCircuitBreakerCustomizer.java
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
.../github/resilience4j/common/ratelimiter/configuration/CompositeRateLimiterCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.resilience4j.common.ratelimiter.configuration; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* the composite of any rate limiter {@link RateLimiterConfigCustomizer} implementations. | ||
*/ | ||
public class CompositeRateLimiterCustomizer { | ||
|
||
private final Map<String, RateLimiterConfigCustomizer> customizerMap = new HashMap<>(); | ||
|
||
public CompositeRateLimiterCustomizer(List<RateLimiterConfigCustomizer> customizers) { | ||
if (customizers != null && !customizers.isEmpty()) { | ||
customizerMap.putAll(customizers.stream() | ||
.collect( | ||
Collectors.toMap(RateLimiterConfigCustomizer::name, Function.identity()))); | ||
} | ||
} | ||
|
||
/** | ||
* @param rateLimiterInstanceName the rate limiter instance name | ||
* @return the found {@link RateLimiterConfigCustomizer} if any . | ||
*/ | ||
public Optional<RateLimiterConfigCustomizer> getRateLimiterConfigCustomizer( | ||
String rateLimiterInstanceName) { | ||
return Optional.ofNullable(customizerMap.get(rateLimiterInstanceName)); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.../io/github/resilience4j/common/ratelimiter/configuration/RateLimiterConfigCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.resilience4j.common.ratelimiter.configuration; | ||
|
||
import io.github.resilience4j.common.CustomizerWithName; | ||
import io.github.resilience4j.ratelimiter.RateLimiterConfig; | ||
|
||
/** | ||
* Enable customization rate limiter configuration builders programmatically. | ||
*/ | ||
public interface RateLimiterConfigCustomizer extends CustomizerWithName { | ||
|
||
/** | ||
* Customize rate limiter configuration builder. | ||
* | ||
* @param configBuilder to be customized | ||
*/ | ||
void customize(RateLimiterConfig.Builder configBuilder); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
...rc/main/java/io/github/resilience4j/common/retry/configuration/RetryConfigCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
package io.github.resilience4j.common.retry.configuration; | ||
|
||
import io.github.resilience4j.common.CustomizerWithName; | ||
import io.github.resilience4j.retry.RetryConfig; | ||
|
||
/** | ||
* Enable customization retry configuration builders programmatically. | ||
*/ | ||
public interface RetryConfigCustomizer { | ||
public interface RetryConfigCustomizer extends CustomizerWithName { | ||
|
||
/** | ||
* Retry configuration builder. | ||
* | ||
* @param configBuilder to be customized | ||
*/ | ||
void customize(RetryConfig.Builder configBuilder); | ||
|
||
/** | ||
* @return name of the retry instance to be customized | ||
*/ | ||
String name(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.