package com.sy.coinage.websocket;

import javax.websocket.Session;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * -保存websocket连接通道类
 *
 * @author lug 2021年6月2日
 */
public class WebSocketSession {

    /**
     * -记录 有多少个客户端【前端浏览器】与服务端【后端】创建连接 的个数 -应该把它设计成线程安全的 , 使用 synchronized 进行操作
     */
    private static Integer connectedClientNum = 0;

    /**
     * -连接数加1
     */
    public static synchronized void increaseConnectedClientNum() {
        connectedClientNum++;
    }

    /**
     * -连接数减1
     */
    public static synchronized void decreaseConnectedClientNum() {
        connectedClientNum--;
    }

    // public static CopyOnWriteArraySet<WebSocketServer> webSocketServers = new
    // CopyOnWriteArraySet<>();
    public static final Map<String, Session> ONLINE_USER_SESSIONS = new ConcurrentHashMap<>();

    public static final Map<String, Map<String, Session>> ONLINE_USER_SESSIONS_NEW = new ConcurrentHashMap<>();

}
