Search in sources :

Example 16 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class QueueManager method take.

public static Object take(String queueName) throws InterruptedException {
    if (!Running) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "The DBModule is not running!");
    }
    AbstractNulsQueue queue = QUEUES_MAP.get(queueName);
    if (null == queue) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "queue not exist");
    }
    Object value = queue.take();
    queue.getStatInfo().takeOne();
    Log.debug("从队列中取出数据,名称:{},当前长度:{}。", queueName, queue.size());
    return value;
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 17 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class QueueManager method initQueue.

/**
 * 将队列加入管理中
 *
 * @param queueName    队列名称
 * @param queue        队列实例
 * @param latelySecond 统计日志时间段
 */
public static void initQueue(String queueName, AbstractNulsQueue queue, int latelySecond) {
    if (!Running) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "The DBModule is not running!");
    }
    if (QUEUES_MAP.containsKey(queueName)) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "queue name is allready exist");
    }
    if (latelySecond == 0) {
        latelySecond = LATELY_SECOND;
    }
    Log.debug("队列初始化,名称:{},单个文件最大大小:{}", queue.getQueueName(), queue.getMaxSize());
    queue.setStatInfo(new StatInfo(queue.getQueueName(), queue.size(), latelySecond));
    QUEUES_MAP.put(queueName, queue);
    LOCK_MAP.put(queueName, new ReentrantLock());
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) StatInfo(io.nuls.core.utils.queue.entity.StatInfo)

Example 18 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class QueueManager method clear.

public static void clear(String queueName) {
    if (!Running) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "The DBModule is not running!");
    }
    AbstractNulsQueue queue = QUEUES_MAP.get(queueName);
    if (null == queue) {
        throw new NulsRuntimeException(ErrorCode.FAILED, "queue not exist");
    }
    Log.debug("清空队列数据,名称:{},当前长度:{}。", queueName, queue.size());
    queue.clear();
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 19 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class ModuleRunner method run.

@Override
public void run() {
    try {
        module = this.loadModule();
        module.setStatus(ModuleStatusEnum.INITIALIZING);
        module.init();
        module.setStatus(ModuleStatusEnum.INITIALIZED);
        module.setStatus(ModuleStatusEnum.STARTING);
        module.start();
        module.setStatus(ModuleStatusEnum.RUNNING);
    } catch (ClassNotFoundException e) {
        module.setStatus(ModuleStatusEnum.EXCEPTION);
        Log.error(e);
        throw new NulsRuntimeException(ErrorCode.FAILED, e);
    } catch (IllegalAccessException e) {
        module.setStatus(ModuleStatusEnum.EXCEPTION);
        Log.error(e);
        throw new NulsRuntimeException(ErrorCode.FAILED, e);
    } catch (InstantiationException e) {
        module.setStatus(ModuleStatusEnum.EXCEPTION);
        Log.error(e);
        throw new NulsRuntimeException(ErrorCode.FAILED, e);
    }
}
Also used : NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 20 with NulsRuntimeException

use of io.nuls.core.exception.NulsRuntimeException in project nuls by nuls-io.

the class TxGroupHandler method onEvent.

@Override
public void onEvent(TxGroupEvent event, String fromId) {
    TxGroup txGroup = event.getEventBody();
    BlockHeader header = temporaryCacheManager.getBlockHeader(event.getEventBody().getBlockHash().getDigestHex());
    if (header == null) {
        return;
    }
    SmallBlock smallBlock = temporaryCacheManager.getSmallBlock(header.getHash().getDigestHex());
    if (null == smallBlock) {
        return;
    }
    Block block = new Block();
    block.setHeader(header);
    List<Transaction> txs = new ArrayList<>();
    for (NulsDigestData txHash : smallBlock.getTxHashList()) {
        Transaction tx = txCacheManager.getTx(txHash);
        if (null == tx) {
            tx = txGroup.getTx(txHash.getDigestHex());
        }
        if (null == tx) {
            throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
        }
        txs.add(tx);
    }
    block.setTxs(txs);
    ValidateResult<RedPunishData> vResult = block.verify();
    if (null == vResult || (vResult.isFailed() && vResult.getErrorCode() != ErrorCode.ORPHAN_TX)) {
        if (vResult.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
            RedPunishData data = vResult.getObject();
            ConsensusMeetingRunner.putPunishData(data);
            networkService.blackNode(fromId, NodePo.BLACK);
        } else {
            networkService.removeNode(fromId, NodePo.YELLOW);
        }
        return;
    }
    blockManager.addBlock(block, false, fromId);
    downloadDataUtils.removeTxGroup(block.getHeader().getHash().getDigestHex());
    AssembledBlockNotice notice = new AssembledBlockNotice();
    notice.setEventBody(header);
    eventBroadcaster.publishToLocal(notice);
}
Also used : TxGroup(io.nuls.consensus.entity.TxGroup) RedPunishData(io.nuls.consensus.entity.RedPunishData) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) AssembledBlockNotice(io.nuls.consensus.event.notice.AssembledBlockNotice)

Aggregations

NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)64 NulsException (io.nuls.core.exception.NulsException)26 IOException (java.io.IOException)11 Transaction (io.nuls.core.chain.entity.Transaction)10 ArrayList (java.util.ArrayList)9 Account (io.nuls.account.entity.Account)7 AbstractNulsQueue (io.nuls.core.utils.queue.intf.AbstractNulsQueue)7 DbSession (io.nuls.db.transactional.annotation.DbSession)6 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)5 ValidateResult (io.nuls.core.validate.ValidateResult)4 Coin (io.nuls.ledger.entity.params.Coin)4 TransactionEvent (io.nuls.ledger.event.TransactionEvent)4 AccountService (io.nuls.account.service.intf.AccountService)3 Block (io.nuls.core.chain.entity.Block)3 AccountPo (io.nuls.db.entity.AccountPo)3 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)3 BlockHashResponse (io.nuls.consensus.entity.BlockHashResponse)2 RedPunishData (io.nuls.consensus.entity.RedPunishData)2 BestCorrectBlock (io.nuls.consensus.entity.block.BestCorrectBlock)2 Agent (io.nuls.consensus.entity.member.Agent)2