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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cn.stylefeng.roses.kernel.socket.api;
 
import cn.stylefeng.roses.kernel.socket.api.exception.SocketException;
import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface;
 
/**
 * Socket通用操作类
 * <p>
 * 可通过该类直接发送消息,每一个Socket实现的子模块必须实现该接口,以提供统一的操作API
 *
 * @author majianguo
 * @date 2021/6/2 上午9:25
 */
public interface SocketOperatorApi {
 
    /**
     * 发送消息到指定会话
     *
     * @param msgType   消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类
     * @param sessionId 会话ID
     * @param msg       消息体
     * @author majianguo
     * @date 2021/6/11 下午2:19
     **/
    void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException;
 
    /**
     * 发送消息到指定用户的所有会话
     * <p>
     * 如果用户同一个消息类型建立了多个会话,则统一全部发送
     *
     * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类
     * @param userId  用户ID
     * @param msg     消息体
     * @author majianguo
     * @date 2021/6/2 上午9:35
     **/
    void sendMsgOfUserSession(String msgType, String userId, Object msg) throws SocketException;
 
    /**
     * 发送消息到所有会话
     *
     * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类
     * @param msg     消息体
     * @author majianguo
     * @date 2021/6/2 上午9:35
     **/
    void sendMsgOfAllUserSession(String msgType, Object msg);
 
    /**
     * 根据会话id关闭会话
     *
     * @param socketId 会话id
     * @author majianguo
     * @date 2021/8/13 16:00
     **/
    void closeSocketBySocketId(String socketId);
 
    /**
     * 监听指定类型消息
     * <p>
     * 1.该方法每调用一次即注册一个监听,同一个消息类型多次调用只有最后一次生效
     *
     * @param msgType           消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类
     * @param callbackInterface 消息监听器
     * @author majianguo
     * @date 2021/6/2 上午9:54
     **/
    void msgTypeCallback(String msgType, SocketMsgCallbackInterface callbackInterface);
}