diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java index c298bc0e1..8bedab61b 100644 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java +++ b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java @@ -9,7 +9,7 @@ import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession; import cn.stylefeng.roses.kernel.socket.business.websocket.message.SocketMessageCenter; import cn.stylefeng.roses.kernel.socket.business.websocket.pojo.WebSocketMessageDTO; import cn.stylefeng.roses.kernel.socket.business.websocket.session.SessionCenter; -import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GettySocketOperator; +import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GunsSocketOperator; import java.util.Collection; import java.util.List; @@ -26,7 +26,7 @@ public class WebSocketOperator implements SocketOperatorApi { @Override public void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException { - SocketSession session = SessionCenter.getSessionBySessionId(sessionId); + SocketSession session = SessionCenter.getSessionBySessionId(sessionId); if (ObjectUtil.isEmpty(session)) { throw new SocketException(SocketExceptionEnum.SESSION_NOT_EXIST); } @@ -39,14 +39,14 @@ public class WebSocketOperator implements SocketOperatorApi { @Override public void sendMsgOfUserSession(String msgType, String userId, Object msg) throws SocketException { // 根据用户ID获取会话 - List> socketSessionList = SessionCenter.getSessionByUserIdAndMsgType(userId); + List> socketSessionList = SessionCenter.getSessionByUserIdAndMsgType(userId); if (ObjectUtil.isEmpty(socketSessionList)) { throw new SocketException(SocketExceptionEnum.SESSION_NOT_EXIST); } WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO(); webSocketMessageDTO.setData(msg); webSocketMessageDTO.setServerMsgType(msgType); - for (SocketSession session : socketSessionList) { + for (SocketSession session : socketSessionList) { // 发送内容 session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO); } @@ -54,12 +54,12 @@ public class WebSocketOperator implements SocketOperatorApi { @Override public void sendMsgOfAllUserSession(String msgType, Object msg) { - Collection>> values = SessionCenter.getSocketSessionMap().values(); + Collection>> values = SessionCenter.getSocketSessionMap().values(); WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO(); webSocketMessageDTO.setData(msg); webSocketMessageDTO.setServerMsgType(msgType); - for (List> sessions : values) { - for (SocketSession session : sessions) { + for (List> sessions : values) { + for (SocketSession session : sessions) { // 找到该类型的通道 if (session.getMessageType().equals(msgType)) { session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO); diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettySocketOperator.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java similarity index 91% rename from kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettySocketOperator.java rename to kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java index 6c07d8841..f5cfddbe8 100644 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettySocketOperator.java +++ b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java @@ -12,14 +12,14 @@ import java.io.IOException; * @author majianguo * @date 2021/6/1 下午3:41 */ -public class GettySocketOperator implements GettyChannelExpandInterFace { +public class GunsSocketOperator implements SocketChannelExpandInterFace { /** * 实际操作的通道 */ private Session socketChannel; - public GettySocketOperator(Session socketChannel) { + public GunsSocketOperator(Session socketChannel) { this.socketChannel = socketChannel; } diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettyChannelExpandInterFace.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java similarity index 81% rename from kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettyChannelExpandInterFace.java rename to kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java index 98e170b31..34639724a 100644 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GettyChannelExpandInterFace.java +++ b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java @@ -10,6 +10,6 @@ import cn.stylefeng.roses.kernel.socket.api.session.SocketSessionOperatorApi; * @author majianguo * @date 2021/6/1 下午3:44 */ -public interface GettyChannelExpandInterFace extends SocketSessionOperatorApi { +public interface SocketChannelExpandInterFace extends SocketSessionOperatorApi { } diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java index 80b14ce3c..16a73b90c 100644 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java +++ b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java @@ -7,7 +7,7 @@ import cn.stylefeng.roses.kernel.socket.api.enums.ServerMessageTypeEnum; import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface; import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession; import cn.stylefeng.roses.kernel.socket.business.websocket.message.SocketMessageCenter; -import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GettySocketOperator; +import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GunsSocketOperator; import cn.stylefeng.roses.kernel.socket.business.websocket.pojo.WebSocketMessageDTO; import cn.stylefeng.roses.kernel.socket.business.websocket.session.SessionCenter; import com.alibaba.fastjson.JSON; @@ -41,7 +41,7 @@ public class WebSocketServer { @OnOpen public void onOpen(Session session, @PathParam("userId") String userId) { // 操作api包装 - GettySocketOperator gettySocketOperator = new GettySocketOperator(session); + GunsSocketOperator GunsSocketOperator = new GunsSocketOperator(session); // 回复消息 WebSocketMessageDTO replyMsg = new WebSocketMessageDTO(); @@ -53,17 +53,17 @@ public class WebSocketServer { replyMsg.setData(session.getId()); // 创建会话对象 - SocketSession socketSession = new SocketSession<>(); + SocketSession socketSession = new SocketSession<>(); socketSession.setSessionId(session.getId()); socketSession.setUserId(userId); - socketSession.setSocketOperatorApi(gettySocketOperator); + socketSession.setSocketOperatorApi(GunsSocketOperator); socketSession.setConnectionTime(System.currentTimeMillis()); // 维护会话 SessionCenter.addSocketSession(socketSession); } finally { // 回复消息 - gettySocketOperator.writeAndFlush(replyMsg); + GunsSocketOperator.writeAndFlush(replyMsg); } } @@ -94,7 +94,7 @@ public class WebSocketServer { WebSocketMessageDTO WebSocketMessageDTO = JSON.parseObject(message, WebSocketMessageDTO.class); // 维护通道是否已初始化 - SocketSession socketSession = SessionCenter.getSessionBySessionId(socketChannel.getId()); + SocketSession socketSession = SessionCenter.getSessionBySessionId(socketChannel.getId()); // 心跳包 if (ObjectUtil.isNotEmpty(socketSession) && ClientMessageTypeEnum.USER_HEART.getCode().equals(WebSocketMessageDTO.getClientMsgType())) { diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java index 7c6fbdad2..872a6f4ee 100644 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java +++ b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java @@ -2,7 +2,7 @@ package cn.stylefeng.roses.kernel.socket.business.websocket.session; import cn.hutool.core.util.ObjectUtil; import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession; -import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GettySocketOperator; +import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GunsSocketOperator; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -21,16 +21,16 @@ public class SessionCenter { /** * 所有会话维护 */ - private static ConcurrentMap>> socketSessionMap = new ConcurrentHashMap<>(); + private static ConcurrentMap>> socketSessionMap = new ConcurrentHashMap<>(); /** * 获取维护的所有会话 * - * @return {@link ConcurrentMap< String, SocketSession>} + * @return {@link ConcurrentMap< String, SocketSession>} * @author majianguo * @date 2021/6/1 下午2:13 **/ - public static ConcurrentMap>> getSocketSessionMap() { + public static ConcurrentMap>> getSocketSessionMap() { return socketSessionMap; } @@ -38,11 +38,11 @@ public class SessionCenter { * 根据用户ID获取会话信息列表 * * @param userId 用户ID - * @return {@link SocketSession } + * @return {@link SocketSession } * @author majianguo * @date 2021/6/1 下午1:48 **/ - public static List> getSessionByUserId(String userId) { + public static List> getSessionByUserId(String userId) { return socketSessionMap.get(userId); } @@ -50,11 +50,11 @@ public class SessionCenter { * 根据用户ID和消息类型获取会话信息列表 * * @param userId 用户ID - * @return {@link SocketSession } + * @return {@link SocketSession } * @author majianguo * @date 2021/6/1 下午1:48 **/ - public static List> getSessionByUserIdAndMsgType(String userId) { + public static List> getSessionByUserIdAndMsgType(String userId) { return socketSessionMap.get(userId); } @@ -62,13 +62,13 @@ public class SessionCenter { * 根据会话ID获取会话信息 * * @param sessionId 会话ID - * @return {@link SocketSession } + * @return {@link SocketSession } * @author majianguo * @date 2021/6/1 下午1:48 **/ - public static SocketSession getSessionBySessionId(String sessionId) { - for (List> values : socketSessionMap.values()) { - for (SocketSession session : values) { + public static SocketSession getSessionBySessionId(String sessionId) { + for (List> values : socketSessionMap.values()) { + for (SocketSession session : values) { if (sessionId.equals(session.getSessionId())) { return session; } @@ -84,8 +84,8 @@ public class SessionCenter { * @author majianguo * @date 2021/6/1 下午1:49 **/ - public static void addSocketSession(SocketSession socketSession) { - List> socketSessions = socketSessionMap.get(socketSession.getUserId()); + public static void addSocketSession(SocketSession socketSession) { + List> socketSessions = socketSessionMap.get(socketSession.getUserId()); if (ObjectUtil.isEmpty(socketSessions)) { socketSessions = new ArrayList<>(); socketSessionMap.put(socketSession.getUserId(), socketSessions); @@ -101,13 +101,13 @@ public class SessionCenter { * @date 2021/6/1 下午3:25 **/ public static void closed(String sessionId) { - Set>>> entrySet = socketSessionMap.entrySet(); - Iterator>>> iterator = entrySet.iterator(); + Set>>> entrySet = socketSessionMap.entrySet(); + Iterator>>> iterator = entrySet.iterator(); while (iterator.hasNext()) { - Map.Entry>> next = iterator.next(); - List> value = next.getValue(); + Map.Entry>> next = iterator.next(); + List> value = next.getValue(); if (ObjectUtil.isNotEmpty(value)) { - value.removeIf(gettySocketOperatorSocketSession -> gettySocketOperatorSocketSession.getSessionId().equals(sessionId)); + value.removeIf(GunsSocketOperatorSocketSession -> GunsSocketOperatorSocketSession.getSessionId().equals(sessionId)); } } }