#
Junjie
2025-11-05 8b4f5b2b23023986db813242cd04f4650537decd
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
package com.zy.core.network;
 
import com.zy.core.ThreadHandler;
import com.zy.core.enums.SlaveType;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
public class DeviceConnectPool {
 
    private static final String _LINK = "_";
 
    private static final Map<String, ThreadHandler> conContain = new ConcurrentHashMap<>();
 
    public static void put(SlaveType type, Integer id, ThreadHandler thread) {
        String key = toKey(type, id);
        remove(type, id);
        conContain.put(key, thread);
    }
 
    public static ThreadHandler get(SlaveType type, Integer id) {
        return conContain.get(toKey(type, id));
    }
 
    public static void remove(SlaveType type, Integer id) {
        Object object = get(type, id);
        if (null == object) {
            return;
        }
        conContain.remove(toKey(type, id));
    }
 
    private static String toKey(SlaveType type, Integer id){
        return type.toString() + _LINK + id;
    }
 
}