package org.matrix.socket;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;



/**
 * 日志消息队列
 * @author huangxiahao
 */
public class LogQueue {

    private static final ConcurrentHashMap<Long, List<String>> LOG_MAP = new ConcurrentHashMap<>();

    public static void add(Long threadId,String log){
        List<String> logList = LOG_MAP.get(threadId);
        if (logList!=null){
            logList.add(log);
        }else {
            logList = new ArrayList<>();
            logList.add(log);
            LOG_MAP.put(threadId,logList);
        }
        //将log发送出去
        sendMessage(threadId,log);
    }

    public static void sendMessage(Long threadId,String log){
        SocketHandler.sendMessage(SocketPool.get(threadId),log);
    }

}
