use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Raft method waitConsensusNodeStarted.
private boolean waitConsensusNodeStarted(ParticipantContext context, NetworkAddress changeConsensusNodeAddress) {
CliClientServiceImpl rpcClient = createRpcClient(context);
Endpoint changeNode = new Endpoint(changeConsensusNodeAddress.getHost(), changeConsensusNodeAddress.getPort());
int i = 0;
while (i <= MAX_RETRY_TIMES) {
i++;
try {
Thread.sleep(SLEEP_MS);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (rpcClient.connect(changeNode)) {
return true;
}
}
return false;
}
use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Raft method createRpcClient.
private CliClientServiceImpl createRpcClient(ParticipantContext context) {
if (context.getProperty(RPC_CLIENT) != null) {
return (CliClientServiceImpl) context.getProperty(RPC_CLIENT);
}
RaftConsensusSettings consensusSetting = (RaftConsensusSettings) getConsensusSetting(context);
RaftNetworkSettings networkSettings = consensusSetting.getNetworkSettings();
SSLSecurity sslSecurity = context.sslSecurity();
// 启用TLS
if (sslSecurity != null && sslSecurity.getKeyStore() != null) {
GmSSLProvider.enableGMSupport(sslSecurity.getProtocol());
setSystemProperty("bolt.client.ssl.enable", "true");
setSystemProperty("bolt.client.ssl.keystore", sslSecurity.getTrustStore());
setSystemProperty("bolt.client.ssl.keystore.password", sslSecurity.getTrustStorePassword());
setSystemProperty("bolt.client.ssl.keystore.type", sslSecurity.getTrustStoreType() == null ? "JKS" : sslSecurity.getTrustStoreType());
setSystemProperty("bolt.ssl.protocol", sslSecurity.getProtocol());
setSystemProperty("bolt.server.ssl.enable", "true");
setSystemProperty("bolt.server.ssl.keystore", sslSecurity.getKeyStore());
setSystemProperty("bolt.server.ssl.keyalias", sslSecurity.getKeyAlias());
setSystemProperty("bolt.server.ssl.keystore.password", sslSecurity.getKeyStorePassword());
setSystemProperty("bolt.server.ssl.keystore.type", sslSecurity.getKeyStoreType());
if (sslSecurity.getEnabledProtocols() != null && sslSecurity.getEnabledProtocols().length > 0) {
setSystemProperty("bolt.ssl.enabled-protocols", String.join(",", sslSecurity.getEnabledProtocols()));
}
if (sslSecurity.getCiphers() != null && sslSecurity.getCiphers().length > 0) {
setSystemProperty("bolt.ssl.ciphers", String.join(",", sslSecurity.getCiphers()));
}
}
CliOptions cliOptions = new CliOptions();
cliOptions.setRpcConnectTimeoutMs(networkSettings.getRpcConnectTimeoutMs());
cliOptions.setRpcDefaultTimeout(networkSettings.getRpcDefaultTimeoutMs());
cliOptions.setRpcInstallSnapshotTimeout(networkSettings.getRpcSnapshotTimeoutMs());
cliOptions.setTimeoutMs(networkSettings.getRpcRequestTimeoutMs() * 2);
cliOptions.setMaxRetry(MAX_RETRY_TIMES);
CliClientServiceImpl clientService = new CliClientServiceImpl();
clientService.init(cliOptions);
context.setProperty(RPC_CLIENT, clientService);
context.setProperty(RPC_QUEST_TIMEOUT_MS, networkSettings.getRpcRequestTimeoutMs() * 2);
return clientService;
}
Aggregations