Skip to content

Commit 9cb825c

Browse files
committed
<feat>(client): add get support configs interfaces.
1 parent 6a7b902 commit 9cb825c

File tree

5 files changed

+164
-3
lines changed

5 files changed

+164
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ext {
3535
// integrationTest.mustRunAfter test
3636
allprojects {
3737
group = 'org.fisco-bcos.java-sdk'
38-
version = '3.7.0'
38+
version = '3.8.0-SNAPSHOT'
3939

4040
apply plugin: 'maven-publish'
4141
apply plugin: 'idea'

src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.Arrays;
2222
import java.util.Collections;
2323
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Optional;
2426
import java.util.concurrent.CompletableFuture;
2527
import java.util.concurrent.ExecutionException;
2628

@@ -92,6 +94,17 @@ public void testClient() {
9294
System.out.println(
9395
"New block, group: " + groupId + ", blockNumber: " + blockNumber));
9496

97+
Map<String, Optional<SystemConfig>> systemConfigList = client.getSystemConfigList();
98+
Assert.assertFalse(systemConfigList.isEmpty());
99+
systemConfigList.forEach(
100+
(key, value) ->
101+
System.out.println(
102+
key
103+
+ " : "
104+
+ (value.isPresent()
105+
? value.get().getSystemConfig()
106+
: "null")));
107+
95108
// test getBlockNumber
96109
BlockNumber blockNumber = client.getBlockNumber();
97110
Assert.assertTrue(blockNumber.getBlockNumber().compareTo(BigInteger.ZERO) >= 0);

src/main/java/org/fisco/bcos/sdk/v3/client/Client.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
package org.fisco.bcos.sdk.v3.client;
1717

1818
import java.math.BigInteger;
19+
import java.util.Map;
20+
import java.util.Optional;
21+
import java.util.Set;
1922
import org.fisco.bcos.sdk.jni.BcosSDKJniObj;
2023
import org.fisco.bcos.sdk.v3.client.protocol.request.Transaction;
2124
import org.fisco.bcos.sdk.v3.client.protocol.response.Abi;
@@ -840,6 +843,13 @@ void getTransactionReceiptAsync(
840843
*/
841844
SystemConfig getSystemConfigByKey(String node, String key);
842845

846+
/**
847+
* Peer operation: get system config list, witch will fetch all config
848+
*
849+
* @return all config value
850+
*/
851+
Map<String, Optional<SystemConfig>> getSystemConfigList();
852+
843853
/**
844854
* Peer operation: async get system config
845855
*
@@ -857,6 +867,20 @@ void getTransactionReceiptAsync(
857867
*/
858868
void getSystemConfigByKeyAsync(String node, String key, RespCallback<SystemConfig> callback);
859869

870+
/**
871+
* async get all connect nodes support keys
872+
*
873+
* @param callback the callback instance
874+
*/
875+
void getSupportSysConfigKeysAsync(RespCallback<Set<String>> callback);
876+
877+
/**
878+
* Peer operation: async get system config list, witch will fetch all config
879+
*
880+
* @param callback the callback instance
881+
*/
882+
void getSystemConfigListAsync(RespCallback<Map<String, Optional<SystemConfig>>> callback);
883+
860884
/**
861885
* Peer operation: get sync status
862886
*

src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
import java.util.Arrays;
2222
import java.util.Collections;
2323
import java.util.List;
24+
import java.util.Map;
2425
import java.util.Objects;
26+
import java.util.Optional;
27+
import java.util.Set;
28+
import java.util.TreeSet;
2529
import java.util.concurrent.CompletableFuture;
30+
import java.util.concurrent.ConcurrentSkipListMap;
2631
import java.util.concurrent.ExecutionException;
32+
import java.util.concurrent.TimeUnit;
33+
import java.util.concurrent.TimeoutException;
2734
import org.fisco.bcos.sdk.jni.BcosSDKJniObj;
2835
import org.fisco.bcos.sdk.jni.rpc.RpcJniObj;
2936
import org.fisco.bcos.sdk.v3.client.exceptions.ClientException;
@@ -1008,6 +1015,32 @@ public SystemConfig getSystemConfigByKey(String node, String key) {
10081015
SystemConfig.class);
10091016
}
10101017

1018+
@Override
1019+
public Map<String, Optional<SystemConfig>> getSystemConfigList() {
1020+
CompletableFuture<Map<String, Optional<SystemConfig>>> future = new CompletableFuture<>();
1021+
this.getSystemConfigListAsync(
1022+
new RespCallback<Map<String, Optional<SystemConfig>>>() {
1023+
@Override
1024+
public void onResponse(Map<String, Optional<SystemConfig>> configMap) {
1025+
future.complete(configMap);
1026+
}
1027+
1028+
@Override
1029+
public void onError(Response errorResponse) {
1030+
future.completeExceptionally(
1031+
new ClientException(
1032+
"getSystemConfigList failed, error: "
1033+
+ errorResponse.getErrorMessage()));
1034+
}
1035+
});
1036+
try {
1037+
return future.get(configOption.getNetworkConfig().getTimeout(), TimeUnit.MILLISECONDS);
1038+
} catch (Exception e) {
1039+
logger.warn("getSystemConfigList failed, error: {}", e.getMessage(), e);
1040+
throw new ClientException("getSystemConfigList failed, error: " + e.getMessage(), e);
1041+
}
1042+
}
1043+
10111044
@Override
10121045
public void getSystemConfigByKeyAsync(String key, RespCallback<SystemConfig> callback) {
10131046
this.getSystemConfigByKeyAsync(nodeToSendRequest, key, callback);
@@ -1026,6 +1059,80 @@ public void getSystemConfigByKeyAsync(
10261059
callback);
10271060
}
10281061

1062+
@Override
1063+
public void getSupportSysConfigKeysAsync(RespCallback<Set<String>> callback) {
1064+
this.getGroupInfoListAsync(
1065+
new RespCallback<BcosGroupInfoList>() {
1066+
@Override
1067+
public void onResponse(BcosGroupInfoList bcosGroupInfoList) {
1068+
Optional<BcosGroupInfo.GroupInfo> group =
1069+
bcosGroupInfoList.getResult().stream()
1070+
.filter(gInfo -> gInfo.getGroupID().equals(getGroup()))
1071+
.findFirst();
1072+
Set<String> keys = new TreeSet<>();
1073+
if (group.isPresent() && !group.get().getNodeList().isEmpty()) {
1074+
group.get()
1075+
.getNodeList()
1076+
.forEach(
1077+
groupNodeInfo -> {
1078+
keys.addAll(groupNodeInfo.getFeatureKeys());
1079+
keys.addAll(groupNodeInfo.getSupportConfigs());
1080+
});
1081+
}
1082+
callback.onResponse(keys);
1083+
}
1084+
1085+
@Override
1086+
public void onError(Response errorResponse) {
1087+
callback.onError(errorResponse);
1088+
}
1089+
});
1090+
}
1091+
1092+
@Override
1093+
public void getSystemConfigListAsync(
1094+
RespCallback<Map<String, Optional<SystemConfig>>> callback) {
1095+
1096+
this.getSupportSysConfigKeysAsync(
1097+
new RespCallback<Set<String>>() {
1098+
@Override
1099+
public void onResponse(Set<String> keys) {
1100+
Map<String, Optional<SystemConfig>> configMap =
1101+
new ConcurrentSkipListMap<>();
1102+
keys.forEach(
1103+
key ->
1104+
getSystemConfigByKeyAsync(
1105+
key,
1106+
new RespCallback<SystemConfig>() {
1107+
@Override
1108+
public void onResponse(
1109+
SystemConfig systemConfig) {
1110+
configMap.put(
1111+
key,
1112+
Optional.ofNullable(systemConfig));
1113+
if (configMap.size() == keys.size()) {
1114+
callback.onResponse(configMap);
1115+
}
1116+
}
1117+
1118+
@Override
1119+
public void onError(Response errorResponse) {
1120+
// maybe not exist
1121+
configMap.put(key, Optional.empty());
1122+
if (configMap.size() == keys.size()) {
1123+
callback.onResponse(configMap);
1124+
}
1125+
}
1126+
}));
1127+
}
1128+
1129+
@Override
1130+
public void onError(Response errorResponse) {
1131+
callback.onError(errorResponse);
1132+
}
1133+
});
1134+
}
1135+
10291136
@Override
10301137
public SyncStatus getSyncStatus(String node) {
10311138
node = Objects.isNull(node) ? "" : node;
@@ -1130,7 +1237,8 @@ public BcosGroupInfo getGroupInfo() {
11301237

11311238
future.complete(response);
11321239
});
1133-
Response response = future.get();
1240+
Response response =
1241+
future.get(configOption.getNetworkConfig().getTimeout(), TimeUnit.MILLISECONDS);
11341242
return ClientImpl.parseResponseIntoJsonRpcResponse(
11351243
JsonRpcMethods.GET_GROUP_INFO, response, BcosGroupInfo.class);
11361244
} catch (ClientException e) {
@@ -1146,6 +1254,12 @@ public BcosGroupInfo getGroupInfo() {
11461254
"getGroupInfo failed for decode the message exception, error message:"
11471255
+ e.getMessage(),
11481256
e);
1257+
} catch (TimeoutException e) {
1258+
logger.error("e: ", e);
1259+
throw new ClientException(
1260+
"getGroupInfo failed for get group info timeout, error message:"
1261+
+ e.getMessage(),
1262+
e);
11491263
}
11501264
}
11511265

src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/BcosGroupNodeInfo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.fasterxml.jackson.databind.type.TypeFactory;
1313
import com.fasterxml.jackson.databind.util.Converter;
1414
import java.io.IOException;
15+
import java.util.ArrayList;
1516
import java.util.List;
1617
import org.fisco.bcos.sdk.v3.client.protocol.model.GroupNodeIniInfo;
1718
import org.fisco.bcos.sdk.v3.model.JsonRpcResponse;
@@ -80,7 +81,8 @@ public static class GroupNodeInfo {
8081
private String name;
8182
private List<ServiceInfo> serviceInfoList;
8283
private Protocol protocol;
83-
private List<String> featureKeys;
84+
private List<String> featureKeys = new ArrayList<>();
85+
private List<String> supportConfigs = new ArrayList<>();
8486

8587
@Override
8688
public String toString() {
@@ -150,6 +152,14 @@ public void setFeatureKeys(List<String> featureKeys) {
150152
this.featureKeys = featureKeys;
151153
}
152154

155+
public List<String> getSupportConfigs() {
156+
return supportConfigs;
157+
}
158+
159+
public void setSupportConfigs(List<String> supportConfigs) {
160+
this.supportConfigs = supportConfigs;
161+
}
162+
153163
static class ServiceInfo {
154164
private String serviceName;
155165
private int type;

0 commit comments

Comments
 (0)