1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.ard.work.domain.cache;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
 
/**
 * 六合tcp服务器缓存
 *
 * @author liusuyi
 * @date 2024年11月01日13:53
 **/
public class TyTcpServerCache {
    // 使用 ConcurrentHashMap 来缓存TCP服务连接状态,key 是 ip:port(服务器地址) value 是连接状态
    private static final ConcurrentHashMap<String, Boolean> tcpServerCache = new ConcurrentHashMap<>();
 
    // 存储TCP服务连接状态到缓存
    public static void putTcpServerCache(String serverId,Boolean state) {
        tcpServerCache.put(serverId, state);
    }
 
    // 从缓存中获取TCP服务连接状态
    public static Boolean getTcpServerCache(String serverId) {
        return tcpServerCache.getOrDefault(serverId,false);
    }
 
    // 删除缓存中的TCP服务连接状态
    public static void removeTcpServerCache(String serverId) {
        tcpServerCache.remove(serverId);
    }
 
    public static Map<String, Boolean> getTcpServerCacheMap() {
        return new HashMap<>(tcpServerCache); // 返回一个副本,避免外部修改原始缓存
    }
 
}