diff --git a/src/main/java/org/bdware/server/action/MasterWSAction.java b/src/main/java/org/bdware/server/action/MasterWSAction.java index 60945c9..4fd73ec 100644 --- a/src/main/java/org/bdware/server/action/MasterWSAction.java +++ b/src/main/java/org/bdware/server/action/MasterWSAction.java @@ -26,10 +26,7 @@ import org.bdware.units.NetworkManager; import org.zz.gmhelper.SM2KeyPair; import org.zz.gmhelper.SM2Util; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -139,7 +136,7 @@ public class MasterWSAction { } } */ - List nodeNames; // nodes' peerID + Set nodeNames; // nodes' peerID // if (contract.getType().equals(ContractExecType.SelfAdaptiveSharding)) { // if (ContractManager.instance.nodeCenterConn.listNodes().length < 3) { // rc.onResult( @@ -160,16 +157,18 @@ public class MasterWSAction { nodeNames = Arrays.stream(nodeNamesStr) .filter(x -> null != x && !x.isEmpty()) - .collect(Collectors.toList()); + .collect(Collectors.toSet()); // } + + SM2KeyPair keyPair = GlobalConf.instance.keyPair; + String masterNode = keyPair.getPublicKeyStr(); + nodeNames.add(masterNode); int nodeSize = nodeNames.size(); // 方式一向NodeCenter发,要求Slave节点主动连接到Master节点. Map requestConnect = new HashMap<>(); requestConnect.put("action", "requestConnectToMaster"); LOGGER.debug(multiPointContractInfo.masterNode); - SM2KeyPair keyPair = GlobalConf.instance.keyPair; - String masterNode = keyPair.getPublicKeyStr(); requestConnect.put("master", masterNode); // 从哪个节点启动,哪个节点就是master requestConnect.put("members", nodeNames); if (contract.getType() == ContractExecType.Sharding) { @@ -256,12 +255,12 @@ public class MasterWSAction { String startReq = JsonUtil.toJson(request); LOGGER.debug("start contract " + startReq); - for (int i = 0; i < nodeSize; ++i) { - String nodeID = nodeNames.get(i); // 根据i获得nodeID + int i = 0; + for (String nodeID : nodeNames) { // for (String nodeID : nodeNames) { // 设置字段 if (multiPointContractInfo.type == ContractExecType.Sharding) { - contract.setShardingId(i); + contract.setShardingId(i++); request.put("contractStr", JsonUtil.toJson(contract)); startReq = JsonUtil.toJson(request); LOGGER.debug("start contract: " + startReq); @@ -292,7 +291,7 @@ public class MasterWSAction { LOGGER.info("success!"); } - private boolean waitForConnection(List nodeNames) { + private boolean waitForConnection(Collection nodeNames) { LOGGER.info("waitForAllNodes:" + JsonUtil.toJson(nodeNames)); for (int i = 0; i < 5; i++) { boolean all = true;