Search in sources :

Example 1 with AbstractNulsQueue

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;
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 2 with AbstractNulsQueue

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();
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 3 with AbstractNulsQueue

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;
    }
}
Also used : BlockingQueueImpl(io.nuls.core.utils.queue.entity.BlockingQueueImpl) AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) PersistentQueue(io.nuls.core.utils.queue.entity.PersistentQueue)

Example 4 with AbstractNulsQueue

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) {
        }
    }
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) FileFormatException(io.nuls.core.utils.queue.fqueue.exception.FileFormatException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 5 with AbstractNulsQueue

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;
}
Also used : AbstractNulsQueue(io.nuls.core.utils.queue.intf.AbstractNulsQueue) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Aggregations

AbstractNulsQueue (io.nuls.core.utils.queue.intf.AbstractNulsQueue)9 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)8 FileFormatException (io.nuls.core.utils.queue.fqueue.exception.FileFormatException)2 IOException (java.io.IOException)2 BlockingQueueImpl (io.nuls.core.utils.queue.entity.BlockingQueueImpl)1 PersistentQueue (io.nuls.core.utils.queue.entity.PersistentQueue)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1