Search in sources :

Example 1 with ConsensusStatusInfo

use of io.nuls.consensus.entity.ConsensusStatusInfo in project nuls by nuls-io.

the class ConsensusManager method initConsensusStatusInfo.

public void initConsensusStatusInfo() {
    List<Consensus<Agent>> agentList = consensusCacheManager.getCachedAgentList();
    ConsensusStatusInfo info = new ConsensusStatusInfo();
    for (String address : NulsContext.LOCAL_ADDRESS_LIST) {
        if (this.seedNodeList.contains(address)) {
            info.setAccount(accountService.getAccount(address));
            info.setStatus(ConsensusStatusEnum.IN.getCode());
            info.setSeed(true);
            break;
        }
        for (Consensus<Agent> agent : agentList) {
            if (agent.getExtend().getPackingAddress().equals(address)) {
                info.setAccount(accountService.getAccount(address));
                info.setStatus(agent.getExtend().getStatus());
                info.setSeed(agent.getExtend().getSeed());
                if (ConsensusStatusEnum.NOT_IN.getCode() != info.getStatus()) {
                    break;
                }
            }
        }
    }
    if (info.getAccount() == null) {
        info.setStatus(ConsensusStatusEnum.NOT_IN.getCode());
    }
    this.consensusStatusInfo = info;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) Consensus(io.nuls.consensus.entity.Consensus) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Example 2 with ConsensusStatusInfo

use of io.nuls.consensus.entity.ConsensusStatusInfo in project nuls by nuls-io.

the class PocConsensusModuleBootstrap method getInfo.

@Override
public String getInfo() {
    if (this.getStatus() == ModuleStatusEnum.UNINITIALIZED || this.getStatus() == ModuleStatusEnum.INITIALIZING) {
        return "";
    }
    StringBuilder str = new StringBuilder();
    str.append("module:[consensus]:\n");
    str.append("consensus status:");
    ConsensusStatusInfo statusInfo = consensusManager.getConsensusStatusInfo();
    if (null == statusInfo) {
        str.append(ConsensusStatusEnum.NOT_IN.getText());
    } else {
        str.append(ConsensusStatusEnum.getConsensusStatusByCode(statusInfo.getStatus()).getText());
    }
    str.append("\n");
    str.append("thread count:");
    List<BaseThread> threadList = TaskManager.getThreadList(this.getModuleId());
    if (null == threadList) {
        str.append(0);
    } else {
        str.append(threadList.size());
        for (BaseThread thread : threadList) {
            str.append("\n");
            str.append(thread.getName());
            str.append("{");
            str.append(thread.getPoolName());
            str.append("}");
        }
    }
    return str.toString();
}
Also used : BaseThread(io.nuls.core.thread.BaseThread) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Example 3 with ConsensusStatusInfo

use of io.nuls.consensus.entity.ConsensusStatusInfo in project nuls by nuls-io.

the class ConsensusCacheManager method init.

public void init() {
    Account self = accountService.getDefaultAccount();
    List<DepositPo> depositPoList = this.depositDao.getList();
    List<AgentPo> agentPoList = this.agentDao.getList();
    Consensus mine = null;
    for (AgentPo po : agentPoList) {
        Consensus<Agent> ca = ConsensusTool.fromPojo(po);
        this.cacheAgent(ca);
        if (null != self && ca.getAddress().equals(self.getAddress().toString())) {
            mine = ca;
        }
    }
    for (DepositPo dpo : depositPoList) {
        Consensus<Deposit> cd = ConsensusTool.fromPojo(dpo);
        this.cacheDeposit(cd);
        if (null != self && null == mine && cd.getAddress().equals(self.getAddress().toString())) {
            mine = cd;
        }
    }
    if (null == self) {
        return;
    }
    ConsensusStatusInfo info = new ConsensusStatusInfo();
    info.setAccount(self);
    if (null == mine) {
        info.setStatus(ConsensusStatusEnum.NOT_IN.getCode());
    } else if (mine.getExtend() instanceof Agent) {
        info.setSeed(((Agent) mine.getExtend()).getSeed());
        info.setStatus(((Agent) mine.getExtend()).getStatus());
    }
    this.updateConsensusStatusInfo(info);
}
Also used : Account(io.nuls.account.entity.Account) Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) DepositPo(io.nuls.db.entity.DepositPo) Consensus(io.nuls.consensus.entity.Consensus) AgentPo(io.nuls.db.entity.AgentPo) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Aggregations

ConsensusStatusInfo (io.nuls.consensus.entity.ConsensusStatusInfo)3 Consensus (io.nuls.consensus.entity.Consensus)2 Agent (io.nuls.consensus.entity.member.Agent)2 Account (io.nuls.account.entity.Account)1 Deposit (io.nuls.consensus.entity.member.Deposit)1 BaseThread (io.nuls.core.thread.BaseThread)1 AgentPo (io.nuls.db.entity.AgentPo)1 DepositPo (io.nuls.db.entity.DepositPo)1