Explorar el Código

Merge branch 'dev' into release
1

wangliang hace 4 años
padre
commit
4bc755f507

+ 45 - 44
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java

@@ -19,7 +19,6 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.signature.SignatureInfo;
 import com.qmth.themis.common.signature.SignatureType;
-import com.qmth.themis.exam.config.ExamConstant;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
 import com.qmth.themis.exam.websocketTemplete.WebSocketMobileMessageTemplete;
 import com.qmth.themis.mq.templete.Concurrently;
@@ -109,9 +108,10 @@ public class WebSocketMobileServer implements Concurrently {
                         webSocketMap.put(this.recordId + "-" + this.source.name(), this);
                     } else {
                         webSocketMap.put(this.recordId + "-" + this.source.name(), this);
-                        addOnlineCount();
+//                        addOnlineCount();
                     }
-                    log.info("用户连接:{},当前在线人数为:{}", this.sessionId, getOnlineCount());
+//                    log.info("用户连接:{},当前在线人数为:{}", this.sessionId, getOnlineCount());
+                    log.info("用户连接:{}", this.sessionId);
                     InetSocketAddress addr = (InetSocketAddress) WebsocketUtil.getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
                     this.ip = addr.toString().replace("/", "").split(":")[0];
 //                    this.sendMessage("ip[" + this.ip + "]连接成功");
@@ -140,7 +140,7 @@ public class WebSocketMobileServer implements Concurrently {
         if (webSocketMap.containsKey(this.recordId + "-" + this.source.name())) {
             webSocketMap.remove(this.recordId + "-" + this.source.name());
             //从set中删除
-            subOnlineCount();
+//            subOnlineCount();
             //判断是否是正常退出
             ExamRecordCacheUtil.setMonitorStatus(recordId, this.source.name(), MonitorStatusSourceEnum.STOP, true);
             ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
@@ -153,7 +153,8 @@ public class WebSocketMobileServer implements Concurrently {
                 webSocketOeServer.sendMessage(websocketDto);
             }
         }
-        log.info("用户退出:{},当前在线人数为:{},updateTime:{}", this.sessionId, getOnlineCount(), this.updateTime);
+//        log.info("用户退出:{},当前在线人数为:{},updateTime:{}", this.sessionId, getOnlineCount(), this.updateTime);
+        log.info("用户退出:{},updateTime:{}", this.sessionId, this.updateTime);
     }
 
     /**
@@ -211,45 +212,45 @@ public class WebSocketMobileServer implements Concurrently {
         this.updateTime = System.currentTimeMillis();
     }
 
-    /**
-     * 获取在线人数
-     *
-     * @return
-     */
-    public synchronized int getOnlineCount() {
-        Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
-        return Objects.isNull(o) ? 0 : (int) o;
-    }
-
-    /**
-     * 在线人数加一
-     */
-    public synchronized void addOnlineCount() {
-        if (redisUtil.lock(SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + this.sessionId, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT)) {
-            Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
-            int count = 0;
-            if (Objects.nonNull(o)) {
-                count = (int) o;
-            }
-            count++;
-            redisUtil.set(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT, count);
-        }
-    }
-
-    /**
-     * 在线人数减一
-     */
-    public synchronized void subOnlineCount() {
-        if (redisUtil.lock(SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + this.sessionId, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT)) {
-            Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
-            int count = 0;
-            if (Objects.nonNull(o)) {
-                count = (int) o;
-            }
-            count--;
-            redisUtil.set(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT, count < 0 ? 0 : count);
-        }
-    }
+//    /**
+//     * 获取在线人数
+//     *
+//     * @return
+//     */
+//    public synchronized int getOnlineCount() {
+//        Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
+//        return Objects.isNull(o) ? 0 : (int) o;
+//    }
+//
+//    /**
+//     * 在线人数加一
+//     */
+//    public synchronized void addOnlineCount() {
+//        if (redisUtil.lock(SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + this.sessionId, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT)) {
+//            Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
+//            int count = 0;
+//            if (Objects.nonNull(o)) {
+//                count = (int) o;
+//            }
+//            count++;
+//            redisUtil.set(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT, count);
+//        }
+//    }
+//
+//    /**
+//     * 在线人数减一
+//     */
+//    public synchronized void subOnlineCount() {
+//        if (redisUtil.lock(SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + this.sessionId, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT)) {
+//            Object o = redisUtil.get(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT);
+//            int count = 0;
+//            if (Objects.nonNull(o)) {
+//                count = (int) o;
+//            }
+//            count--;
+//            redisUtil.set(SystemConstant.WEBSOCKET_OE_ONLINE_COUNT, count < 0 ? 0 : count);
+//        }
+//    }
 
     public static ConcurrentHashMap<String, WebSocketMobileServer> getWebSocketMap() {
         return webSocketMap;