Search in sources :

Example 1 with QueryManagerInfoRequest

use of com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequest in project jdchain-core by blockchain-jd-com.

the class RaftMessageService method queryPeersManagerInfo.

private List<MonitorNodeNetwork> queryPeersManagerInfo(List<PeerId> peerIds) throws InterruptedException {
    if (!isReloadMonitorNode) {
        return monitorNodeNetworks;
    }
    synchronized (monitorLock) {
        if (!isReloadMonitorNode) {
            return monitorNodeNetworks;
        }
        final List<MonitorNodeNetwork> nodeNetworkList = Collections.synchronizedList(new ArrayList<>(peerIds.size()));
        CountDownLatch countDownLatch = new CountDownLatch(peerIds.size());
        QueryManagerInfoRequest infoRequest = new QueryManagerInfoRequest();
        for (PeerId peerId : peerIds) {
            try {
                clientService.getRpcClient().invokeAsync(peerId.getEndpoint(), infoRequest, (o, e) -> {
                    try {
                        if (e != null) {
                            LoggerUtils.errorIfEnabled(LOGGER, "queryPeersManagerInfo response error, peer id: {}", peerId, e);
                        } else {
                            RpcResponse response = (RpcResponse) o;
                            QueryManagerInfoRequestProcessor.ManagerInfoResponse managerInfoResponse = QueryManagerInfoRequestProcessor.ManagerInfoResponse.fromBytes(response.getResult());
                            MonitorNodeNetwork monitorNodeNetwork = new MonitorNodeNetwork(managerInfoResponse.getHost(), managerInfoResponse.getConsensusPort(), managerInfoResponse.getManagerPort(), managerInfoResponse.isConsensusSSLEnabled(), managerInfoResponse.isManagerSSLEnabled());
                            nodeNetworkList.add(monitorNodeNetwork);
                        }
                    } catch (Exception exception) {
                        LoggerUtils.errorIfEnabled(LOGGER, "handle queryPeersManagerInfo response error", e);
                    } finally {
                        countDownLatch.countDown();
                    }
                }, this.rpcTimeoutMs);
            } catch (Exception e) {
                LOGGER.error("queryPeersManagerInfo error", e);
                countDownLatch.countDown();
            }
        }
        countDownLatch.await(this.rpcTimeoutMs * peerIds.size(), TimeUnit.MILLISECONDS);
        monitorNodeNetworks.clear();
        monitorNodeNetworks.addAll(nodeNetworkList);
        isReloadMonitorNode = false;
    }
    return monitorNodeNetworks;
}
Also used : QueryManagerInfoRequest(com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequest) QueryManagerInfoRequestProcessor(com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequestProcessor) RpcResponse(com.jd.blockchain.consensus.raft.rpc.RpcResponse) RemotingException(com.alipay.sofa.jraft.error.RemotingException) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 2 with QueryManagerInfoRequest

use of com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequest in project jdchain-core by blockchain-jd-com.

the class BlockSyncService method getConsensusNodeManagerInfo.

private ServiceEndpoint getConsensusNodeManagerInfo(Endpoint remoteEndpoint) {
    try {
        QueryManagerInfoRequest request = new QueryManagerInfoRequest();
        RpcResponse response = (RpcResponse) rpcClient.invokeSync(remoteEndpoint, request, requestTimeoutMs);
        QueryManagerInfoRequestProcessor.ManagerInfoResponse infoResponse = QueryManagerInfoRequestProcessor.ManagerInfoResponse.fromBytes(response.getResult());
        return new ServiceEndpoint(remoteEndpoint.getIp(), infoResponse.getManagerPort(), infoResponse.isManagerSSLEnabled());
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : QueryManagerInfoRequest(com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequest) QueryManagerInfoRequestProcessor(com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequestProcessor) RpcResponse(com.jd.blockchain.consensus.raft.rpc.RpcResponse) ServiceEndpoint(com.jd.httpservice.agent.ServiceEndpoint) BlockSyncException(com.jd.blockchain.consensus.raft.consensus.BlockSyncException)

Aggregations

QueryManagerInfoRequest (com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequest)2 QueryManagerInfoRequestProcessor (com.jd.blockchain.consensus.raft.rpc.QueryManagerInfoRequestProcessor)2 RpcResponse (com.jd.blockchain.consensus.raft.rpc.RpcResponse)2 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 RemotingException (com.alipay.sofa.jraft.error.RemotingException)1 BlockSyncException (com.jd.blockchain.consensus.raft.consensus.BlockSyncException)1 ServiceEndpoint (com.jd.httpservice.agent.ServiceEndpoint)1