use of com.jd.blockchain.consensus.NodeNetworkAddresses in project jdchain-core by blockchain-jd-com.
the class BftsmartNodeServer method appExecuteUnordered.
@Override
public byte[] appExecuteUnordered(byte[] bytes, MessageContext messageContext) {
if (Arrays.equals(MonitorService.LOAD_MONITOR, bytes)) {
try {
// 获取加载管理端口的信息
View currView = this.replica.getReplicaContext().getCurrentView();
Map<Integer, NodeNetwork> addresses = currView.getAddresses();
TreeMap<Integer, NodeNetwork> tree = new TreeMap<>();
for (Map.Entry<Integer, NodeNetwork> entry : addresses.entrySet()) {
tree.put(entry.getKey(), entry.getValue());
}
Collection<NodeNetwork> nodeNetworks = tree.values();
NodeNetworkAddresses nodeNetworkAddresses = nodeNetworkAddresses(new ArrayList<>(nodeNetworks));
return BinaryProtocol.encode(nodeNetworkAddresses, NodeNetworkAddresses.class);
} catch (Exception e) {
// 返回启动异常的错误
throw new IllegalStateException(String.format("BftSmartNodeServer[%s] is still not started !", serverId));
}
}
return messageHandle.processUnordered(bytes).get();
}
use of com.jd.blockchain.consensus.NodeNetworkAddresses in project jdchain-core by blockchain-jd-com.
the class LedgerPeersManager method updateTopology.
public Set<NetworkAddress> updateTopology() {
for (Map.Entry<NetworkAddress, LedgerPeerConnectionManager> entry : connections.entrySet()) {
try {
logger.debug("UpdateTopology by {}", entry.getKey());
NodeNetworkAddresses nodeNetworkAddresses = entry.getValue().loadMonitors();
if (null != nodeNetworkAddresses) {
NodeNetworkAddress[] nodeAddresses = nodeNetworkAddresses.getNodeNetworkAddresses();
if (nodeAddresses != null && nodeAddresses.length > 0) {
Set<NetworkAddress> addresses = new HashSet<>();
boolean satisfied = true;
for (NodeNetworkAddress address : nodeAddresses) {
// 存在端口小于0的情况则不使用此次查询结果
if (address.getMonitorPort() > 0) {
addresses.add(new NetworkAddress(address.getHost(), address.getMonitorPort(), address.isMonitorSecure()));
} else {
satisfied = false;
break;
}
}
if (satisfied) {
logger.debug("UpdateTopology by {} : {}", entry.getKey(), addresses);
return addresses;
} else {
continue;
}
}
}
} catch (Exception e) {
logger.warn("UpdateTopology by {}", entry.getKey(), e);
}
}
return null;
}
Aggregations