Search in sources :

Example 1 with NodeNetworkAddresses

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();
}
Also used : NodeNetworkAddresses(com.jd.blockchain.consensus.NodeNetworkAddresses) TreeMap(java.util.TreeMap) View(bftsmart.reconfiguration.views.View) BlockRollbackException(com.jd.blockchain.ledger.BlockRollbackException) LRUMap(org.apache.commons.collections4.map.LRUMap) Map(java.util.Map) TreeMap(java.util.TreeMap) NodeNetwork(bftsmart.reconfiguration.views.NodeNetwork)

Example 2 with NodeNetworkAddresses

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;
}
Also used : NodeNetworkAddress(com.jd.blockchain.consensus.NodeNetworkAddress) NodeNetworkAddress(com.jd.blockchain.consensus.NodeNetworkAddress) NetworkAddress(utils.net.NetworkAddress) NodeNetworkAddresses(com.jd.blockchain.consensus.NodeNetworkAddresses) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

NodeNetworkAddresses (com.jd.blockchain.consensus.NodeNetworkAddresses)2 NodeNetwork (bftsmart.reconfiguration.views.NodeNetwork)1 View (bftsmart.reconfiguration.views.View)1 NodeNetworkAddress (com.jd.blockchain.consensus.NodeNetworkAddress)1 BlockRollbackException (com.jd.blockchain.ledger.BlockRollbackException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LRUMap (org.apache.commons.collections4.map.LRUMap)1 NetworkAddress (utils.net.NetworkAddress)1