Search in sources :

Example 1 with MessageBusComponent

use of com.jd.blockchain.consensus.raft.msgbus.MessageBusComponent in project jdchain-core by blockchain-jd-com.

the class RaftNodeServer method init.

private void init(RaftServerSettings raftServerSettings) {
    this.selfPeerId = nodeSettingsToPeerId(raftServerSettings.getReplicaSettings());
    this.configuration = new Configuration();
    for (NodeSettings nodeSettings : raftServerSettings.getConsensusSettings().getNodes()) {
        this.configuration.addPeer(nodeSettingsToPeerId(nodeSettings));
    }
    if (!this.configuration.contains(selfPeerId)) {
        this.configuration.addPeer(selfPeerId);
    }
    this.clientAuthencationService = new RaftClientAuthenticationService(this);
    CliOptions cliOptions = new CliOptions();
    cliOptions.setRpcConnectTimeoutMs(this.serverSettings.getRaftNetworkSettings().getRpcConnectTimeoutMs());
    cliOptions.setRpcDefaultTimeout(this.serverSettings.getRaftNetworkSettings().getRpcDefaultTimeoutMs());
    cliOptions.setRpcInstallSnapshotTimeout(this.serverSettings.getRaftNetworkSettings().getRpcSnapshotTimeoutMs());
    this.raftClientService = (CliClientServiceImpl) ((CliServiceImpl) RaftServiceFactory.createAndInitCliService(cliOptions)).getCliClientService();
    this.rpcClient = this.raftClientService.getRpcClient();
    this.nodeOptions = initNodeOptions(raftServerSettings);
    this.nodeOptions.setInitialConf(this.configuration);
    LedgerRepository ledgerRepository = LedgerManageUtils.getLedgerRepository(this.ledgerHashDigest);
    this.messageBus = new MessageBusComponent(raftServerSettings.getRaftSettings().getDisruptorBufferSize());
    this.blockSerializer = new SimpleBlockSerializerService();
    this.blockProposer = new BlockProposerService(ledgerRepository);
    this.blockCommitter = new BlockCommitService(this.realmName, this.messageHandle, ledgerRepository, this.messageBus);
    this.blockCommitter.registerCallBack((BlockCommitCallback) blockProposer);
    this.blockSyncer = new BlockSyncService(ledgerRepository, this.rpcClient, this.serverSettings.getRaftNetworkSettings().getRpcRequestTimeoutMs());
    messageBus.register(BLOCK_CATCH_UP_TOPIC, (Subcriber) this.blockSyncer);
    this.stateMachine = new RaftConsensusStateMachine(this.blockCommitter, this.blockSerializer, this.blockSyncer, ledgerRepository);
    this.nodeOptions.setFsm(stateMachine);
    RaftNodeServerContext.getInstance().init(this);
}
Also used : MessageBusComponent(com.jd.blockchain.consensus.raft.msgbus.MessageBusComponent) NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) Configuration(com.alipay.sofa.jraft.conf.Configuration) CliServiceImpl(com.alipay.sofa.jraft.core.CliServiceImpl) LedgerRepository(com.jd.blockchain.ledger.core.LedgerRepository) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Aggregations

Configuration (com.alipay.sofa.jraft.conf.Configuration)1 CliServiceImpl (com.alipay.sofa.jraft.core.CliServiceImpl)1 CliOptions (com.alipay.sofa.jraft.option.CliOptions)1 NodeSettings (com.jd.blockchain.consensus.NodeSettings)1 MessageBusComponent (com.jd.blockchain.consensus.raft.msgbus.MessageBusComponent)1 RaftNodeSettings (com.jd.blockchain.consensus.raft.settings.RaftNodeSettings)1 LedgerRepository (com.jd.blockchain.ledger.core.LedgerRepository)1