package com.engine.kq.timer;

import com.engine.common.entity.BizLogContext;
import com.engine.common.timer.BizLogQueue;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

public class KQQueue {

    private static int limitNum = 3000;
    public static Queue<KQTaskBean> queue = new ConcurrentLinkedQueue<KQTaskBean>();

    public static List<KQTaskBean> pollLimitList() {
        List<KQTaskBean> list = null;
      KQTaskBean tmp = null;
        while((tmp = queue.poll()) != null) {
            if (tmp == null) {
                break;
            }
            if (list == null) {
                list = new ArrayList<KQTaskBean>(limitNum);
            }
            list.add(tmp);
            if (list.size() >= limitNum) {
                break;
            }
        }
        return list;
    }

    public static void clear() {
        queue.clear();
    }

    public static int getLimitNum() {
        return limitNum;
    }

    public static void writeTasks(List<KQTaskBean> tasks) {
        if (tasks== null) {
            return;
        }
        for (KQTaskBean taskBean:tasks) {
          queue.offer(taskBean);
        }
    }

    public static void writeTask(KQTaskBean task) {
      if (task== null) {
        return;
      }
      queue.offer(task);
    }
}
