goupan
2024-04-03 5506e9a45e717ffcb67ec313b5a4e8206d9b3a39
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
39
40
41
42
43
44
45
46
package cn.stylefeng.roses.kernel.socket.business.websocket.message;
 
import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 会话消息中心
 * <p>
 * 维护所有消息类型对应的处理器
 *
 * @author majianguo
 * @date 2021/6/1 下午2:20
 */
public class SocketMessageCenter {
 
    /**
     * 所有消息监听器维护
     */
    private static final Map<String, SocketMsgCallbackInterface> MESSAGE_LISTENER_MAP = new HashMap<>();
 
    /**
     * 设置消息类型的监听器
     *
     * @param msgType  消息类型
     * @param listener 监听器
     * @author majianguo
     * @date 2021/6/1 下午2:25
     **/
    public static void setMessageListener(String msgType, SocketMsgCallbackInterface listener) {
        MESSAGE_LISTENER_MAP.put(msgType, listener);
    }
 
    /**
     * 获取消息监听器
     *
     * @param msgType 消息类型
     * @return {@link SocketMsgCallbackInterface}
     * @author majianguo
     * @date 2021/6/1 下午2:26
     **/
    public static SocketMsgCallbackInterface getSocketMsgCallbackInterface(String msgType) {
        return MESSAGE_LISTENER_MAP.get(msgType);
    }
}