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.
Commonize framework configs (ReactiveX#460)
- Loading branch information
Showing
107 changed files
with
1,609 additions
and
1,733 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
resilience4j-core/src/main/java/io/github/resilience4j/core/ClassUtils.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,24 @@ | ||
package io.github.resilience4j.core; | ||
|
||
import io.github.resilience4j.core.lang.Nullable; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.util.function.Predicate; | ||
|
||
public class ClassUtils { | ||
|
||
@Nullable | ||
@SuppressWarnings("unchecked") | ||
public static <T> Predicate<T> instantiatePredicateClass(Class<? extends Predicate<T>> clazz) { | ||
try { | ||
Constructor<? extends Predicate> c = clazz.getConstructor(); | ||
if (c != null) { | ||
return c.newInstance(); | ||
} else { | ||
return null; | ||
} | ||
} catch (Exception e) { | ||
throw new InstantiationException("Unable to create instance of class: " + clazz.getName(), e); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
resilience4j-core/src/main/java/io/github/resilience4j/core/InstantiationException.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,23 @@ | ||
package io.github.resilience4j.core; | ||
|
||
public class InstantiationException extends RuntimeException { | ||
|
||
public InstantiationException() { | ||
} | ||
|
||
public InstantiationException(String message) { | ||
super(message); | ||
} | ||
|
||
public InstantiationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public InstantiationException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public InstantiationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
resilience4j-core/src/main/java/io/github/resilience4j/core/StringUtils.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,11 @@ | ||
package io.github.resilience4j.core; | ||
|
||
import io.github.resilience4j.core.lang.Nullable; | ||
|
||
public class StringUtils { | ||
|
||
public static boolean isNotEmpty(@Nullable String string) { | ||
return string != null && !string.isEmpty(); | ||
} | ||
|
||
} |
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
130 changes: 130 additions & 0 deletions
130
...io/github/resilience4j/common/bulkhead/configuration/BulkheadConfigurationProperties.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,130 @@ | ||
/* | ||
* Copyright 2019 Dan Maas | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.github.resilience4j.common.bulkhead.configuration; | ||
|
||
import io.github.resilience4j.core.ConfigurationNotFoundException; | ||
import io.github.resilience4j.core.StringUtils; | ||
import io.github.resilience4j.core.lang.Nullable; | ||
|
||
import javax.validation.constraints.Min; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BulkheadConfigurationProperties { | ||
|
||
private Map<String, InstanceProperties> instances = new HashMap<>(); | ||
private Map<String, InstanceProperties> configs = new HashMap<>(); | ||
|
||
public io.github.resilience4j.bulkhead.BulkheadConfig createBulkheadConfig(InstanceProperties instanceProperties) { | ||
if (StringUtils.isNotEmpty(instanceProperties.getBaseConfig())) { | ||
InstanceProperties baseProperties = configs.get(instanceProperties.getBaseConfig()); | ||
if (baseProperties == null) { | ||
throw new ConfigurationNotFoundException(instanceProperties.getBaseConfig()); | ||
} | ||
return buildConfigFromBaseConfig(baseProperties, instanceProperties); | ||
} | ||
return buildBulkheadConfig(io.github.resilience4j.bulkhead.BulkheadConfig.custom(), instanceProperties); | ||
} | ||
|
||
private io.github.resilience4j.bulkhead.BulkheadConfig buildConfigFromBaseConfig(InstanceProperties baseProperties, InstanceProperties instanceProperties) { | ||
io.github.resilience4j.bulkhead.BulkheadConfig baseConfig = buildBulkheadConfig(io.github.resilience4j.bulkhead.BulkheadConfig.custom(), baseProperties); | ||
return buildBulkheadConfig(io.github.resilience4j.bulkhead.BulkheadConfig.from(baseConfig), instanceProperties); | ||
} | ||
|
||
private io.github.resilience4j.bulkhead.BulkheadConfig buildBulkheadConfig(io.github.resilience4j.bulkhead.BulkheadConfig.Builder builder, InstanceProperties instanceProperties) { | ||
if (instanceProperties.getMaxConcurrentCalls() != null) { | ||
builder.maxConcurrentCalls(instanceProperties.getMaxConcurrentCalls()); | ||
} | ||
if (instanceProperties.getMaxWaitTime() != null) { | ||
builder.maxWaitTime(instanceProperties.getMaxWaitTime()); | ||
} | ||
return builder.build(); | ||
} | ||
|
||
@Nullable | ||
public InstanceProperties getBackendProperties(String backend) { | ||
return instances.get(backend); | ||
} | ||
|
||
public Map<String, InstanceProperties> getInstances() { | ||
return instances; | ||
} | ||
|
||
/** | ||
* For backwards compatibility when setting backends in configuration properties. | ||
*/ | ||
public Map<String, InstanceProperties> getBackends() { | ||
return instances; | ||
} | ||
|
||
public Map<String, InstanceProperties> getConfigs() { | ||
return configs; | ||
} | ||
|
||
/** | ||
* Bulkhead config adapter for integration with Ratpack. {@link #maxWaitTime} should | ||
* almost always be set to 0, so the compute threads would not be blocked upon execution. | ||
*/ | ||
public static class InstanceProperties { | ||
|
||
@Min(1) | ||
private Integer maxConcurrentCalls; | ||
@Min(0) | ||
private Long maxWaitTime; | ||
@Nullable | ||
private String baseConfig; | ||
@Min(1) | ||
private Integer eventConsumerBufferSize = 100; | ||
|
||
public InstanceProperties setMaxConcurrentCalls(Integer maxConcurrentCalls) { | ||
this.maxConcurrentCalls = maxConcurrentCalls; | ||
return this; | ||
} | ||
|
||
public InstanceProperties setMaxWaitTime(Long maxWaitTime) { | ||
this.maxWaitTime = maxWaitTime; | ||
return this; | ||
} | ||
|
||
public InstanceProperties setBaseConfig(String baseConfig) { | ||
this.baseConfig = baseConfig; | ||
return this; | ||
} | ||
|
||
public InstanceProperties eventConsumerBufferSize(Integer eventConsumerBufferSize) { | ||
this.eventConsumerBufferSize = eventConsumerBufferSize; | ||
return this; | ||
} | ||
|
||
public Integer getMaxConcurrentCalls() { | ||
return maxConcurrentCalls; | ||
} | ||
|
||
public Long getMaxWaitTime() { | ||
return maxWaitTime; | ||
} | ||
|
||
public String getBaseConfig() { | ||
return baseConfig; | ||
} | ||
|
||
public Integer getEventConsumerBufferSize() { | ||
return eventConsumerBufferSize; | ||
} | ||
|
||
} | ||
|
||
} |
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
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
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.