Skip to content

Commit 0186bea

Browse files
committed
feat: diff spi properties
1 parent 3edbe01 commit 0186bea

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

sdk-component/src/main/java/group/rxcloud/capa/component/configstore/CapaConfigStoreBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public CapaConfigStore build() {
8787
private CapaConfigStore buildCapaConfigStore() {
8888
// load spi capa config store impl
8989
try {
90-
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.get();
90+
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("configuration");
9191
String capaConfigStoreClassPath = properties.getProperty(CapaConfigStore.class.getName());
9292
Class<? extends CapaConfigStore> aClass = (Class<? extends CapaConfigStore>) Class.forName(capaConfigStoreClassPath);
9393
Constructor<? extends CapaConfigStore> constructor = aClass.getConstructor(CapaObjectSerializer.class);

sdk-component/src/main/java/group/rxcloud/capa/component/http/CapaHttpBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private CapaHttp buildCapaHttp() {
108108

109109
// load spi capa http impl
110110
try {
111-
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.get();
111+
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("rpc");
112112
String capaHttpClassPath = properties.getProperty(CapaHttp.class.getName());
113113
Class<? extends CapaHttp> aClass = (Class<? extends CapaHttp>) Class.forName(capaHttpClassPath);
114114
Constructor<? extends CapaHttp> constructor = aClass.getConstructor(OkHttpClient.class, CapaObjectSerializer.class);

sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/config/CapaProperties.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
import java.io.InputStream;
2121
import java.io.InputStreamReader;
2222
import java.nio.charset.StandardCharsets;
23+
import java.util.Map;
24+
import java.util.Objects;
2325
import java.util.Properties;
26+
import java.util.concurrent.ConcurrentHashMap;
27+
import java.util.function.Function;
2428
import java.util.function.Supplier;
2529

26-
import static group.rxcloud.capa.infrastructure.constants.CapaConstants.Properties.CAPA_COMPONENT_PROPERTIES;
30+
import static group.rxcloud.capa.infrastructure.constants.CapaConstants.Properties.CAPA_COMPONENT_PROPERTIES_PREFIX;
31+
import static group.rxcloud.capa.infrastructure.constants.CapaConstants.Properties.CAPA_COMPONENT_PROPERTIES_SUFFIX;
2732

2833
/**
2934
* Global properties for Capa's SDK, using Supplier so they are dynamically resolved.
@@ -53,23 +58,26 @@ public abstract class CapaProperties {
5358
public static final Supplier<Integer> HTTP_CLIENT_READ_TIMEOUT_SECONDS = () -> DEFAULT_HTTP_CLIENT_READTIMEOUTSECONDS;
5459

5560
/**
56-
* Capa's component properties.
61+
* Capa's component properties cache map.
5762
*/
58-
private static final Properties COMPONENT_PROPERTIES = loadCapaComponentProperties();
63+
private static final Map<String, Properties> COMPONENT_PROPERTIES_MAP = new ConcurrentHashMap<>();
5964

6065
/**
6166
* Capa's component properties.
6267
*/
63-
public static final Supplier<Properties> COMPONENT_PROPERTIES_SUPPLIER = () -> COMPONENT_PROPERTIES;
68+
public static final Function<String, Properties> COMPONENT_PROPERTIES_SUPPLIER = (componentDomain) ->
69+
COMPONENT_PROPERTIES_MAP.computeIfAbsent(componentDomain, s -> loadCapaComponentProperties(componentDomain));
6470

65-
private static Properties loadCapaComponentProperties() {
66-
try (InputStream in = CapaProperties.class.getResourceAsStream(CAPA_COMPONENT_PROPERTIES)) {
71+
private static Properties loadCapaComponentProperties(final String componentDomain) {
72+
Objects.requireNonNull(componentDomain, "componentDomain not found.");
73+
final String fileName = CAPA_COMPONENT_PROPERTIES_PREFIX + componentDomain.toLowerCase() + CAPA_COMPONENT_PROPERTIES_SUFFIX;
74+
try (InputStream in = CapaProperties.class.getResourceAsStream(fileName)) {
6775
InputStreamReader inputStreamReader = new InputStreamReader(in, StandardCharsets.UTF_8);
6876
Properties properties = new Properties();
6977
properties.load(inputStreamReader);
7078
return properties;
7179
} catch (IOException e) {
72-
throw new IllegalArgumentException(CAPA_COMPONENT_PROPERTIES + " file not found.");
80+
throw new IllegalArgumentException(fileName + " file not found.");
7381
}
7482
}
7583
}

sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/constants/CapaConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface Environments {
2727

2828
interface Properties {
2929

30-
String CAPA_COMPONENT_PROPERTIES = "/capa-component.properties";
30+
String CAPA_COMPONENT_PROPERTIES_PREFIX = "/capa-component-";
31+
String CAPA_COMPONENT_PROPERTIES_SUFFIX = ".properties";
3132
}
3233
}

sdk-spi/src/main/java/group/rxcloud/capa/spi/config/CapaSpiProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class CapaSpiProperties {
3535
public static CapaSpiOptionsLoader getSpiOptionsLoader() {
3636
// load spi capa http impl
3737
try {
38-
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.get();
38+
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply("rpc");
3939
String classPath = properties.getProperty(CapaSpiOptionsLoader.class.getName());
4040
Class<? extends CapaSpiOptionsLoader> aClass = (Class<? extends CapaSpiOptionsLoader>) Class.forName(classPath);
4141
Constructor<? extends CapaSpiOptionsLoader> constructor = aClass.getConstructor();

0 commit comments

Comments
 (0)