use of io.nuls.core.utils.queue.intf.AbstractNulsQueue 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.utils.queue.intf.AbstractNulsQueue 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.utils.queue.intf.AbstractNulsQueue in project nuls by nuls-io.
the class QueueService method createQueue.
/**
* 创建一个持久化队列
*
* @param queueName 队列名称
* @param maxSize 单个文件最大大小fileLimitLength/非持久化时是队列的最大长度
* @param latelySecond 统计日志打印时间段
* @return 是否创建成功
*/
public boolean createQueue(String queueName, Long maxSize, boolean persist, int latelySecond) {
try {
AbstractNulsQueue queue = null;
if (persist) {
queue = new PersistentQueue(queueName, maxSize);
} else {
queue = new BlockingQueueImpl(queueName, Integer.parseInt(maxSize + ""));
}
QueueManager.initQueue(queueName, queue, latelySecond);
return true;
} catch (Exception e) {
Log.error("", e);
return false;
}
}
use of io.nuls.core.utils.queue.intf.AbstractNulsQueue in project nuls by nuls-io.
the class QueueManager method logQueueStatus.
public static void logQueueStatus() {
for (Map.Entry<String, AbstractNulsQueue> entry : QUEUES_MAP.entrySet()) {
try {
AbstractNulsQueue queue = entry.getValue();
long nowIn = queue.getStatInfo().getInCount().get();
long nowOut = queue.getStatInfo().getOutCount().get();
long latelyInTps = (nowIn - queue.getStatInfo().getLastInCount()) / queue.getStatInfo().getLatelySecond();
long latelyOutTps = (nowOut - queue.getStatInfo().getLastOutCount()) / queue.getStatInfo().getLatelySecond();
queue.getStatInfo().setLatelyInTps(latelyInTps);
queue.getStatInfo().setLatelyOutTps(latelyOutTps);
queue.getStatInfo().setLastInCount(nowIn);
queue.getStatInfo().setLastOutCount(nowOut);
Log.info(queue.getStatInfo().toString());
} catch (Exception e) {
}
}
}
use of io.nuls.core.utils.queue.intf.AbstractNulsQueue in project nuls by nuls-io.
the class QueueManager method poll.
public static Object poll(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");
}
Object obj = queue.poll();
boolean notNull = null != obj;
if (notNull) {
queue.getStatInfo().takeOne();
Log.debug("从队列中取出数据,名称:{},当前长度:{}。", queueName, queue.size());
}
return obj;
}
Aggregations