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());
|
}
|
}
|