Search in sources :

Example 81 with Configuration

use of com.alipay.sofa.jraft.conf.Configuration 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)81 PeerId (com.alipay.sofa.jraft.entity.PeerId)54 Test (org.junit.Test)28 Node (com.alipay.sofa.jraft.Node)20 Endpoint (com.alipay.sofa.jraft.util.Endpoint)20 Status (com.alipay.sofa.jraft.Status)18 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)18 RaftGroupService (com.alipay.sofa.jraft.RaftGroupService)9 SynchronizedClosure (com.alipay.sofa.jraft.closure.SynchronizedClosure)8 File (java.io.File)8 ArrayList (java.util.ArrayList)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)7 ConfigurationEntry (com.alipay.sofa.jraft.conf.ConfigurationEntry)5 Task (com.alipay.sofa.jraft.entity.Task)5 CliOptions (com.alipay.sofa.jraft.option.CliOptions)5 LogId (com.alipay.sofa.jraft.entity.LogId)4 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)4 LogEntry (com.alipay.sofa.jraft.entity.LogEntry)3 RaftException (com.alipay.sofa.jraft.error.RaftException)3