jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.protocol.gps;
 
import com.ld.igds.io.notify.NotifyGpsMacService;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.SpringUtil;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
 
import lombok.extern.slf4j.Slf4j;
 
/**
 * @author:
 * @description:
 * @version:
 * @data:
 */
@Slf4j
public class SessionListener implements IoSessionListener {
 
    private NotifyGpsMacService notifyGpsMacService;
 
    @Override
    public void onCreate(IoSession session) {
 
        // 添加自定义业务ID
        session.setBusinessKey(ContextUtil.getServerKey(session.getAddress(),
                session.getPort()));
 
        log.info("GPS成功连接,IP={},port={}", session.getAddress(),
                session.getPort());
 
        if (null == notifyGpsMacService) {
            notifyGpsMacService = SpringUtil.getBean(NotifyGpsMacService.class);
        }
 
        notifyGpsMacService.onCreate(session.getAddress(), session.getPort());
    }
 
    @Override
    public void onDestroy(IoSession session) {
 
        log.info("GPS断开连接,IP={},port={}", session.getAddress(),
                session.getPort());
 
        if (null == notifyGpsMacService) {
            notifyGpsMacService = SpringUtil.getBean(NotifyGpsMacService.class);
        }
 
        notifyGpsMacService.onDestroy(session.getAddress(), session.getPort());
    }
}