21
21
import java .util .Arrays ;
22
22
import java .util .Collections ;
23
23
import java .util .List ;
24
+ import java .util .Map ;
24
25
import java .util .Objects ;
26
+ import java .util .Optional ;
27
+ import java .util .Set ;
28
+ import java .util .TreeSet ;
25
29
import java .util .concurrent .CompletableFuture ;
30
+ import java .util .concurrent .ConcurrentSkipListMap ;
26
31
import java .util .concurrent .ExecutionException ;
32
+ import java .util .concurrent .TimeUnit ;
33
+ import java .util .concurrent .TimeoutException ;
27
34
import org .fisco .bcos .sdk .jni .BcosSDKJniObj ;
28
35
import org .fisco .bcos .sdk .jni .rpc .RpcJniObj ;
29
36
import org .fisco .bcos .sdk .v3 .client .exceptions .ClientException ;
@@ -1008,6 +1015,32 @@ public SystemConfig getSystemConfigByKey(String node, String key) {
1008
1015
SystemConfig .class );
1009
1016
}
1010
1017
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
+
1011
1044
@ Override
1012
1045
public void getSystemConfigByKeyAsync (String key , RespCallback <SystemConfig > callback ) {
1013
1046
this .getSystemConfigByKeyAsync (nodeToSendRequest , key , callback );
@@ -1026,6 +1059,80 @@ public void getSystemConfigByKeyAsync(
1026
1059
callback );
1027
1060
}
1028
1061
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
+
1029
1136
@ Override
1030
1137
public SyncStatus getSyncStatus (String node ) {
1031
1138
node = Objects .isNull (node ) ? "" : node ;
@@ -1130,7 +1237,8 @@ public BcosGroupInfo getGroupInfo() {
1130
1237
1131
1238
future .complete (response );
1132
1239
});
1133
- Response response = future .get ();
1240
+ Response response =
1241
+ future .get (configOption .getNetworkConfig ().getTimeout (), TimeUnit .MILLISECONDS );
1134
1242
return ClientImpl .parseResponseIntoJsonRpcResponse (
1135
1243
JsonRpcMethods .GET_GROUP_INFO , response , BcosGroupInfo .class );
1136
1244
} catch (ClientException e ) {
@@ -1146,6 +1254,12 @@ public BcosGroupInfo getGroupInfo() {
1146
1254
"getGroupInfo failed for decode the message exception, error message:"
1147
1255
+ e .getMessage (),
1148
1256
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 );
1149
1263
}
1150
1264
}
1151
1265
0 commit comments