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;
}
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());
}
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();
}
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);
}
}
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);
}
Aggregations