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 ;
34
+ import java .util .stream .Collectors ;
27
35
import org .fisco .bcos .sdk .jni .BcosSDKJniObj ;
28
36
import org .fisco .bcos .sdk .jni .rpc .RpcJniObj ;
29
37
import org .fisco .bcos .sdk .v3 .client .exceptions .ClientException ;
58
66
import org .fisco .bcos .sdk .v3 .client .protocol .response .SystemConfig ;
59
67
import org .fisco .bcos .sdk .v3 .client .protocol .response .TotalTransactionCount ;
60
68
import org .fisco .bcos .sdk .v3 .config .ConfigOption ;
69
+ import org .fisco .bcos .sdk .v3 .contract .precompiled .sysconfig .SystemConfigFeature ;
61
70
import org .fisco .bcos .sdk .v3 .contract .precompiled .sysconfig .SystemConfigService ;
62
71
import org .fisco .bcos .sdk .v3 .crypto .CryptoSuite ;
63
72
import org .fisco .bcos .sdk .v3 .model .CryptoType ;
@@ -1008,6 +1017,32 @@ public SystemConfig getSystemConfigByKey(String node, String key) {
1008
1017
SystemConfig .class );
1009
1018
}
1010
1019
1020
+ @ Override
1021
+ public Map <String , Optional <SystemConfig >> getSystemConfigList () {
1022
+ CompletableFuture <Map <String , Optional <SystemConfig >>> future = new CompletableFuture <>();
1023
+ this .getSystemConfigListAsync (
1024
+ new RespCallback <Map <String , Optional <SystemConfig >>>() {
1025
+ @ Override
1026
+ public void onResponse (Map <String , Optional <SystemConfig >> configMap ) {
1027
+ future .complete (configMap );
1028
+ }
1029
+
1030
+ @ Override
1031
+ public void onError (Response errorResponse ) {
1032
+ future .completeExceptionally (
1033
+ new ClientException (
1034
+ "getSystemConfigList failed, error: "
1035
+ + errorResponse .getErrorMessage ()));
1036
+ }
1037
+ });
1038
+ try {
1039
+ return future .get (configOption .getNetworkConfig ().getTimeout (), TimeUnit .MILLISECONDS );
1040
+ } catch (Exception e ) {
1041
+ logger .warn ("getSystemConfigList failed, error: {}" , e .getMessage (), e );
1042
+ throw new ClientException ("getSystemConfigList failed, error: " + e .getMessage (), e );
1043
+ }
1044
+ }
1045
+
1011
1046
@ Override
1012
1047
public void getSystemConfigByKeyAsync (String key , RespCallback <SystemConfig > callback ) {
1013
1048
this .getSystemConfigByKeyAsync (nodeToSendRequest , key , callback );
@@ -1026,6 +1061,89 @@ public void getSystemConfigByKeyAsync(
1026
1061
callback );
1027
1062
}
1028
1063
1064
+ @ Override
1065
+ public void getSupportSysConfigKeysAsync (RespCallback <Set <String >> callback ) {
1066
+ this .getGroupInfoListAsync (
1067
+ new RespCallback <BcosGroupInfoList >() {
1068
+ @ Override
1069
+ public void onResponse (BcosGroupInfoList bcosGroupInfoList ) {
1070
+ Optional <BcosGroupInfo .GroupInfo > group =
1071
+ bcosGroupInfoList .getResult ().stream ()
1072
+ .filter (gInfo -> gInfo .getGroupID ().equals (getGroup ()))
1073
+ .findFirst ();
1074
+ Set <String > keys = new TreeSet <>();
1075
+ keys .addAll (
1076
+ Arrays .stream (SystemConfigFeature .Features .values ())
1077
+ .map (SystemConfigFeature .Features ::toString )
1078
+ .collect (Collectors .toList ()));
1079
+ keys .addAll (SystemConfigService .getConfigKeys ());
1080
+ if (group .isPresent () && !group .get ().getNodeList ().isEmpty ()) {
1081
+ group .get ()
1082
+ .getNodeList ()
1083
+ .forEach (
1084
+ groupNodeInfo -> {
1085
+ keys .addAll (groupNodeInfo .getFeatureKeys ());
1086
+ keys .addAll (groupNodeInfo .getSupportConfigs ());
1087
+ });
1088
+ }
1089
+ callback .onResponse (keys );
1090
+ }
1091
+
1092
+ @ Override
1093
+ public void onError (Response errorResponse ) {
1094
+ callback .onError (errorResponse );
1095
+ }
1096
+ });
1097
+ }
1098
+
1099
+ @ Override
1100
+ public void getSystemConfigListAsync (
1101
+ RespCallback <Map <String , Optional <SystemConfig >>> callback ) {
1102
+
1103
+ this .getSupportSysConfigKeysAsync (
1104
+ new RespCallback <Set <String >>() {
1105
+ @ Override
1106
+ public void onResponse (Set <String > keys ) {
1107
+ Map <String , Optional <SystemConfig >> configMap =
1108
+ new ConcurrentSkipListMap <>();
1109
+ if (keys .isEmpty ()) {
1110
+ callback .onResponse (configMap );
1111
+ return ;
1112
+ }
1113
+ keys .forEach (
1114
+ key ->
1115
+ getSystemConfigByKeyAsync (
1116
+ key ,
1117
+ new RespCallback <SystemConfig >() {
1118
+ @ Override
1119
+ public void onResponse (
1120
+ SystemConfig systemConfig ) {
1121
+ configMap .put (
1122
+ key ,
1123
+ Optional .ofNullable (systemConfig ));
1124
+ if (configMap .size () == keys .size ()) {
1125
+ callback .onResponse (configMap );
1126
+ }
1127
+ }
1128
+
1129
+ @ Override
1130
+ public void onError (Response errorResponse ) {
1131
+ // maybe not exist
1132
+ configMap .put (key , Optional .empty ());
1133
+ if (configMap .size () == keys .size ()) {
1134
+ callback .onResponse (configMap );
1135
+ }
1136
+ }
1137
+ }));
1138
+ }
1139
+
1140
+ @ Override
1141
+ public void onError (Response errorResponse ) {
1142
+ callback .onError (errorResponse );
1143
+ }
1144
+ });
1145
+ }
1146
+
1029
1147
@ Override
1030
1148
public SyncStatus getSyncStatus (String node ) {
1031
1149
node = Objects .isNull (node ) ? "" : node ;
@@ -1130,7 +1248,8 @@ public BcosGroupInfo getGroupInfo() {
1130
1248
1131
1249
future .complete (response );
1132
1250
});
1133
- Response response = future .get ();
1251
+ Response response =
1252
+ future .get (configOption .getNetworkConfig ().getTimeout (), TimeUnit .MILLISECONDS );
1134
1253
return ClientImpl .parseResponseIntoJsonRpcResponse (
1135
1254
JsonRpcMethods .GET_GROUP_INFO , response , BcosGroupInfo .class );
1136
1255
} catch (ClientException e ) {
@@ -1146,6 +1265,12 @@ public BcosGroupInfo getGroupInfo() {
1146
1265
"getGroupInfo failed for decode the message exception, error message:"
1147
1266
+ e .getMessage (),
1148
1267
e );
1268
+ } catch (TimeoutException e ) {
1269
+ logger .error ("e: " , e );
1270
+ throw new ClientException (
1271
+ "getGroupInfo failed for get group info timeout, error message:"
1272
+ + e .getMessage (),
1273
+ e );
1149
1274
}
1150
1275
}
1151
1276
@@ -1604,41 +1729,44 @@ public static <T extends JsonRpcResponse<?>> T parseResponseIntoJsonRpcResponse(
1604
1729
// parse the response into JsonRPCResponse
1605
1730
T jsonRpcResponse =
1606
1731
getObjectMapper ().readValue (response .getContent (), responseType );
1607
- if (jsonRpcResponse .getError () != null ) {
1608
- logger .error (
1609
- "parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, retErrorMessage: {}, retErrorCode: {}" ,
1732
+ // error code inside json rpc response
1733
+ if (jsonRpcResponse .hasError ()) {
1734
+ logger .info (
1735
+ "parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, msg: {}, code: {}, rawRsp: {}" ,
1610
1736
method ,
1611
1737
jsonRpcResponse .getError ().getMessage (),
1612
- jsonRpcResponse .getError ().getCode ());
1738
+ jsonRpcResponse .getError ().getCode (),
1739
+ response .getContentString ());
1613
1740
throw new ClientException (
1614
1741
jsonRpcResponse .getError ().getCode (),
1615
1742
jsonRpcResponse .getError ().getMessage (),
1616
- "ErrorMessage : " + jsonRpcResponse .getError ().getMessage ());
1743
+ "msg : " + jsonRpcResponse .getError ().getMessage ());
1617
1744
}
1618
1745
return jsonRpcResponse ;
1619
1746
} else {
1620
- logger .error (
1621
- "parseResponseIntoJsonRpcResponse failed, method: {}, retErrorMessage : {}, retErrorCode : {}" ,
1747
+ logger .info (
1748
+ "parseResponseIntoJsonRpcResponse failed, method: {}, msg : {}, code: {}, rawRsp : {}" ,
1622
1749
method ,
1623
1750
response .getErrorMessage (),
1624
- response .getErrorCode ());
1751
+ response .getErrorCode (),
1752
+ response .getContent ());
1625
1753
throw new ClientException (
1626
1754
response .getErrorCode (),
1627
1755
response .getErrorMessage (),
1628
- "get response failed, errorCode : "
1756
+ "get response failed, code : "
1629
1757
+ response .getErrorCode ()
1630
- + ", error message : "
1758
+ + ", msg : "
1631
1759
+ response .getErrorMessage ());
1632
1760
}
1633
1761
} catch (ClientException e ) {
1634
- logger .error (
1762
+ logger .info (
1635
1763
"parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}" ,
1636
1764
response ,
1637
1765
e .getMessage (),
1638
1766
e );
1639
1767
throw e ;
1640
1768
} catch (Exception e ) {
1641
- logger .error (
1769
+ logger .info (
1642
1770
"parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}" ,
1643
1771
response ,
1644
1772
e .getMessage (),
0 commit comments