|
@@ -33,7 +33,6 @@ import javax.websocket.*;
|
|
import javax.websocket.server.ServerEndpoint;
|
|
import javax.websocket.server.ServerEndpoint;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
-import java.net.InetSocketAddress;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -61,7 +60,7 @@ public class WebSocketOeServer implements Concurrently {
|
|
*/
|
|
*/
|
|
private Session session = null;
|
|
private Session session = null;
|
|
|
|
|
|
- private String sessionId = null, ip = null, deviceId = null, websocketSessionId = null;
|
|
|
|
|
|
+ private String deviceId = null, websocketSessionId = null;
|
|
|
|
|
|
private Long recordId = null, updateTime = null;
|
|
private Long recordId = null, updateTime = null;
|
|
|
|
|
|
@@ -80,7 +79,6 @@ public class WebSocketOeServer implements Concurrently {
|
|
TBSession tbSession = (TBSession) session.getUserProperties().get(Constants.HEADER_TB_SESSION);
|
|
TBSession tbSession = (TBSession) session.getUserProperties().get(Constants.HEADER_TB_SESSION);
|
|
this.session = session;
|
|
this.session = session;
|
|
session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
|
|
session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
|
|
- this.sessionId = tbSession.getId();
|
|
|
|
websocketSessionId = String.valueOf(UidUtil.nextId());
|
|
websocketSessionId = String.valueOf(UidUtil.nextId());
|
|
if (webSocketMap.containsKey(this.websocketSessionId)) {
|
|
if (webSocketMap.containsKey(this.websocketSessionId)) {
|
|
throw new BusinessException(ExceptionResultEnum.REPEAT_CONNECT_ERROR);
|
|
throw new BusinessException(ExceptionResultEnum.REPEAT_CONNECT_ERROR);
|
|
@@ -89,21 +87,17 @@ public class WebSocketOeServer implements Concurrently {
|
|
addOnlineCount();
|
|
addOnlineCount();
|
|
}
|
|
}
|
|
log.info("考试记录:{},WS连接创建:{},在线人数:{}", this.recordId, this.websocketSessionId, getOnlineCount());
|
|
log.info("考试记录:{},WS连接创建:{},在线人数:{}", this.recordId, this.websocketSessionId, getOnlineCount());
|
|
- InetSocketAddress addr = (InetSocketAddress) WebsocketUtil
|
|
|
|
- .getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
|
|
|
|
- this.ip = addr.toString().replace("/", "").split(":")[0];
|
|
|
|
- log.info("ip[:{}]连接成功", this.ip);
|
|
|
|
//修改record相关状态需要强制上锁
|
|
//修改record相关状态需要强制上锁
|
|
String lockKey = SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + ":client:" + recordId;
|
|
String lockKey = SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + ":client:" + recordId;
|
|
redisUtil.waitLock(lockKey, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT);
|
|
redisUtil.waitLock(lockKey, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT);
|
|
try {
|
|
try {
|
|
- WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.ip, this.websocketSessionId,
|
|
|
|
|
|
+ WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.websocketSessionId,
|
|
WebsocketStatusEnum.ON_LINE);
|
|
WebsocketStatusEnum.ON_LINE);
|
|
} finally {
|
|
} finally {
|
|
redisUtil.releaseLock(lockKey);
|
|
redisUtil.releaseLock(lockKey);
|
|
}
|
|
}
|
|
this.updateTime = System.currentTimeMillis();
|
|
this.updateTime = System.currentTimeMillis();
|
|
- tranMap = WebsocketUtil.initWebsocket(this.recordId, null, this.deviceId, this.ip, this.updateTime);
|
|
|
|
|
|
+ tranMap = WebsocketUtil.initWebsocket(this.recordId, this.deviceId, this.updateTime);
|
|
MqUtil mqUtil = SpringContextHolder.getBean(MqUtil.class);
|
|
MqUtil mqUtil = SpringContextHolder.getBean(MqUtil.class);
|
|
MqDtoService mqDtoService = SpringContextHolder.getBean(MqDtoService.class);
|
|
MqDtoService mqDtoService = SpringContextHolder.getBean(MqDtoService.class);
|
|
Map mqMap = new HashMap<>();
|
|
Map mqMap = new HashMap<>();
|
|
@@ -135,8 +129,7 @@ public class WebSocketOeServer implements Concurrently {
|
|
String currentId = ExamRecordCacheUtil.getClientWebsocketId(recordId);
|
|
String currentId = ExamRecordCacheUtil.getClientWebsocketId(recordId);
|
|
if (this.websocketSessionId != null && this.websocketSessionId.equals(currentId)) {
|
|
if (this.websocketSessionId != null && this.websocketSessionId.equals(currentId)) {
|
|
long timestamp = System.currentTimeMillis();
|
|
long timestamp = System.currentTimeMillis();
|
|
- WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.ip, this.websocketSessionId,
|
|
|
|
- WebsocketStatusEnum.OFF_LINE);
|
|
|
|
|
|
+ WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.websocketSessionId, WebsocketStatusEnum.OFF_LINE);
|
|
//判断是否是正常退出
|
|
//判断是否是正常退出
|
|
TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
|
|
TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
|
|
tOeExamRecordService.sendExamRecordDataSaveMq(this.recordId, timestamp);
|
|
tOeExamRecordService.sendExamRecordDataSaveMq(this.recordId, timestamp);
|