From 14bd16efad2a007ee6e814eb95f166edc36cce93 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Thu, 11 Jan 2024 20:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.1.0=E3=80=91=E3=80=90socket=E3=80=91?= =?UTF-8?q?=E7=A7=BB=E9=99=A4socket=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-socket/pom.xml | 36 ---- kernel-d-socket/socket-api/README.md | 1 - kernel-d-socket/socket-api/pom.xml | 41 ---- .../kernel/socket/api/SocketOperatorApi.java | 70 ------- .../socket/api/constants/SocketConstants.java | 45 ----- .../api/enums/ClientMessageTypeEnum.java | 34 ---- .../api/enums/ServerMessageTypeEnum.java | 34 ---- .../api/enums/SystemMessageTypeEnum.java | 39 ---- .../socket/api/exception/SocketException.java | 47 ----- .../exception/enums/SocketExceptionEnum.java | 66 ------- .../message/SocketMsgCallbackInterface.java | 24 --- .../api/session/SocketSessionOperatorApi.java | 70 ------- .../api/session/pojo/SocketSession.java | 55 ------ .../socket-business-websocket/pom.xml | 45 ----- .../websocket/config/WebSocketConfig.java | 20 -- .../message/SocketMessageCenter.java | 46 ----- .../websocket/operator/WebSocketOperator.java | 80 -------- .../operator/channel/GunsSocketOperator.java | 59 ------ .../channel/SocketChannelExpandInterFace.java | 15 -- .../websocket/pojo/WebSocketMessageDTO.java | 48 ----- .../websocket/server/WebSocketServer.java | 182 ------------------ .../websocket/session/SessionCenter.java | 145 -------------- .../socket-spring-boot-starter/README.md | 1 - .../socket-spring-boot-starter/pom.xml | 29 --- .../ProjectSocketAutoConfiguration.java | 54 ------ .../main/resources/META-INF/spring.factories | 2 - .../system-spring-boot-starter/pom.xml | 7 - pom.xml | 3 - 28 files changed, 1298 deletions(-) delete mode 100644 kernel-d-socket/pom.xml delete mode 100644 kernel-d-socket/socket-api/README.md delete mode 100644 kernel-d-socket/socket-api/pom.xml delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/SocketOperatorApi.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java delete mode 100644 kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java delete mode 100644 kernel-d-socket/socket-business-websocket/pom.xml delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/config/WebSocketConfig.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/message/SocketMessageCenter.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java delete mode 100644 kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java delete mode 100644 kernel-d-socket/socket-spring-boot-starter/README.md delete mode 100644 kernel-d-socket/socket-spring-boot-starter/pom.xml delete mode 100644 kernel-d-socket/socket-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/socket/starter/ProjectSocketAutoConfiguration.java delete mode 100644 kernel-d-socket/socket-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/kernel-d-socket/pom.xml b/kernel-d-socket/pom.xml deleted file mode 100644 index 3543520c4..000000000 --- a/kernel-d-socket/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - roses-kernel - 8.1.0 - ../pom.xml - - - kernel-d-socket - - pom - - - socket-api - socket-business-websocket - socket-spring-boot-starter - - - - - - - cn.stylefeng.roses - kernel-a-rule - ${roses.version} - - - - - - diff --git a/kernel-d-socket/socket-api/README.md b/kernel-d-socket/socket-api/README.md deleted file mode 100644 index 7d4af1501..000000000 --- a/kernel-d-socket/socket-api/README.md +++ /dev/null @@ -1 +0,0 @@ -socket模块的api \ No newline at end of file diff --git a/kernel-d-socket/socket-api/pom.xml b/kernel-d-socket/socket-api/pom.xml deleted file mode 100644 index 8ccf29346..000000000 --- a/kernel-d-socket/socket-api/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - kernel-d-socket - 8.1.0 - ../pom.xml - - - socket-api - - jar - - - - - - cn.stylefeng.roses - config-api - ${roses.version} - - - - - com.gettyio - getty-core - - - - - com.gettyio - getty-expansion - - - - - diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/SocketOperatorApi.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/SocketOperatorApi.java deleted file mode 100644 index 5d08b3429..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/SocketOperatorApi.java +++ /dev/null @@ -1,70 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api; - -import cn.stylefeng.roses.kernel.socket.api.exception.SocketException; -import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface; - -/** - * Socket通用操作类 - *

- * 可通过该类直接发送消息,每一个Socket实现的子模块必须实现该接口,以提供统一的操作API - * - * @author majianguo - * @since 2021/6/2 上午9:25 - */ -public interface SocketOperatorApi { - - /** - * 发送消息到指定会话 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param sessionId 会话ID - * @param msg 消息体 - * @author majianguo - * @since 2021/6/11 下午2:19 - **/ - void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException; - - /** - * 发送消息到指定用户的所有会话 - *

- * 如果用户同一个消息类型建立了多个会话,则统一全部发送 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param userId 用户ID - * @param msg 消息体 - * @author majianguo - * @since 2021/6/2 上午9:35 - **/ - void sendMsgOfUserSession(String msgType, String userId, Object msg) throws SocketException; - - /** - * 发送消息到所有会话 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param msg 消息体 - * @author majianguo - * @since 2021/6/2 上午9:35 - **/ - void sendMsgOfAllUserSession(String msgType, Object msg); - - /** - * 根据会话id关闭会话 - * - * @param socketId 会话id - * @author majianguo - * @since 2021/8/13 16:00 - **/ - void closeSocketBySocketId(String socketId); - - /** - * 监听指定类型消息 - *

- * 1.该方法每调用一次即注册一个监听,同一个消息类型多次调用只有最后一次生效 - * - * @param msgType 消息类型可参考{@link cn.stylefeng.roses.kernel.socket.api.enums}枚举类 - * @param callbackInterface 消息监听器 - * @author majianguo - * @since 2021/6/2 上午9:54 - **/ - void msgTypeCallback(String msgType, SocketMsgCallbackInterface callbackInterface); -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java deleted file mode 100644 index 6ac8fc91c..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/constants/SocketConstants.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.constants; - -/** - * socket 模块常量 - * - * @author majianguo - * @since 2021/6/1 上午11:21 - */ -public interface SocketConstants { - - /** - * socket模块的名称 - */ - String SOCKET_MODULE_NAME = "kernel-d-socket"; - - /** - * 异常枚举的步进值 - */ - String SOCKET_EXCEPTION_STEP_CODE = "30"; - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java deleted file mode 100644 index 0ed749b2c..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ClientMessageTypeEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 客户端消息类型枚举 - *

- * 说明:该枚举适用于服务器接收到客户端发来的消息,判断消息类型时使用 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum ClientMessageTypeEnum { - - /** - * 用户连接鉴权 - */ - USER_CONNECTION_AUTHENTICATION("200000", "用户连接鉴权"), - - /** - * 用户心跳消息类型 - */ - USER_HEART("299999", "用户心跳消息类型"); - - private final String code; - - private final String name; - - ClientMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java deleted file mode 100644 index e17feb395..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/ServerMessageTypeEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 服务端消息类型枚举 - *

- * 说明:该枚举适用于服务器推送给客户端消息时使用 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum ServerMessageTypeEnum { - - /** - * 系统通知消息类型 - */ - SYS_NOTICE_MSG_TYPE("100001", "系统通知消息类型"), - - /** - * 连接消息回复 - */ - SYS_REPLY_MSG_TYPE("100002", "连接消息回复"); - - private final String code; - - private final String name; - - ServerMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java deleted file mode 100644 index bb78f4a15..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/enums/SystemMessageTypeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.enums; - -import lombok.Getter; - -/** - * 服务端监听器枚举 - *

- * 说明:该枚举适用于服务端监听首次连接和断开连接 - * - * @author majianguo - * @since 2021/6/3 上午9:14 - */ -@Getter -public enum SystemMessageTypeEnum { - - /** - * 监听首次连接 - */ - SYS_LISTENER_ONOPEN("S00001", "监听首次连接"), - - /** - * 监听断开连接 - */ - SYS_LISTENER_ONCLOSE("S00002", "监听断开连接"), - - /** - * 监听异常信息 - */ - SYS_LISTENER_ONERROR("S00003", "监听异常信息"); - - private final String code; - - private final String name; - - SystemMessageTypeEnum(String code, String name) { - this.code = code; - this.name = name; - } -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java deleted file mode 100644 index 68c0add02..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/SocketException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.exception; - -import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; -import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; -import cn.stylefeng.roses.kernel.socket.api.constants.SocketConstants; - -/** - * Socket模块异常 - * - * @author majianguo - * @since 2021/6/1 上午11:23 - */ -public class SocketException extends ServiceException { - - public SocketException(AbstractExceptionEnum exception) { - super(SocketConstants.SOCKET_MODULE_NAME, exception); - } - - public SocketException(String errorCode, String userTip) { - super(SocketConstants.SOCKET_MODULE_NAME, errorCode, userTip); - } - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java deleted file mode 100644 index cc3f99dca..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/exception/enums/SocketExceptionEnum.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.exception.enums; - -import cn.stylefeng.roses.kernel.rule.constants.RuleConstants; -import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; -import cn.stylefeng.roses.kernel.socket.api.constants.SocketConstants; -import lombok.Getter; - -/** - * Socket模块相关异常枚举 - * - * @author majianguo - * @since 2021/6/1 上午11:25 - */ -@Getter -public enum SocketExceptionEnum implements AbstractExceptionEnum { - - /** - * Socket操作异常 - */ - SOCKET_ERROR(RuleConstants.THIRD_ERROR_TYPE_CODE + SocketConstants.SOCKET_EXCEPTION_STEP_CODE + "01", "操作异常,具体信息为:{}"), - - /** - * 会话不存在 - */ - SESSION_NOT_EXIST(RuleConstants.THIRD_ERROR_TYPE_CODE + SocketConstants.SOCKET_EXCEPTION_STEP_CODE + "02", "会话不存在"); - - /** - * 错误编码 - */ - private final String errorCode; - - /** - * 提示用户信息 - */ - private final String userTip; - - SocketExceptionEnum(String errorCode, String userTip) { - this.errorCode = errorCode; - this.userTip = userTip; - } - -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java deleted file mode 100644 index d719d95fe..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/message/SocketMsgCallbackInterface.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.message; - -import cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession; - -/** - * Socket消息接收回调接口 - * - * @author majianguo - * @since 2021/6/2 上午9:53 - */ -@FunctionalInterface -public interface SocketMsgCallbackInterface { - - /** - * 收到消息的回调 - * - * @param msgType 消息类型 - * @param msg 消息体 - * @param socketSession 本次通信的会话 - * @author majianguo - * @since 2021/6/2 上午9:51 - **/ - void callback(String msgType, Object msg, SocketSession socketSession); -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java deleted file mode 100644 index 460783f11..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/SocketSessionOperatorApi.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.api.session; - -/** - * socket会话操作接口 - *

- * 该接口面向会话,须基于会话的通道调用。 - * 该接口支持扩展,可参考WebSocket模块中{@link cn.stylefeng.roses.kernel.socket.websocket.operator.channel}包下的类 - * - * @author majianguo - * @since 2021/6/1 上午11:46 - */ -public interface SocketSessionOperatorApi { - - /** - * 写出数据,经过责任链 - * - * @author majianguo - * @since 2021/6/1 上午11:48 - **/ - void writeAndFlush(Object obj); - - /** - * 写出数据,不经过责任链 - * - * @author majianguo - * @since 2021/6/1 上午11:48 - **/ - void writeToChannel(Object obj); - - /** - * 关闭会话 - * - * @author majianguo - * @since 2021/6/1 上午11:48 - **/ - void close(); - - /** - * 是否存活 - * - * @return {@link boolean} - * @author majianguo - * @since 2021/6/1 上午11:50 - **/ - boolean isInvalid(); -} diff --git a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java b/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java deleted file mode 100644 index 275cb58a1..000000000 --- a/kernel-d-socket/socket-api/src/main/java/cn/stylefeng/roses/kernel/socket/api/session/pojo/SocketSession.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.api.session.pojo; - -import cn.stylefeng.roses.kernel.socket.api.session.SocketSessionOperatorApi; -import lombok.Data; - -/** - * Socket会话 - * - * @author majianguo - * @since 2021/6/1 上午11:28 - */ -@Data -public class SocketSession { - - /** - * 会话ID,每一个新建的会话都有(目前使用通道ID) - */ - private String sessionId; - - /** - * 会话唯一标识 - */ - private String userId; - - /** - * 该会话监听的消息类型 - */ - private String messageType; - - /** - * token信息 - */ - private String token; - - /** - * 连接时间 - */ - private Long connectionTime; - - /** - * 最后活跃时间 - */ - private Long lastActiveTime; - - /** - * 操作API - */ - private T socketOperatorApi; - - /** - * 自定义数据 - */ - private Object data; - -} diff --git a/kernel-d-socket/socket-business-websocket/pom.xml b/kernel-d-socket/socket-business-websocket/pom.xml deleted file mode 100644 index 69ec464f6..000000000 --- a/kernel-d-socket/socket-business-websocket/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - kernel-d-socket - 8.1.0 - ../pom.xml - - - socket-business-websocket - - - - - - org.springframework.boot - spring-boot-starter-websocket - - - - - org.springframework.boot - spring-boot-starter-web - - - - - cn.stylefeng.roses - socket-api - ${roses.version} - - - - - cn.stylefeng.roses - auth-api - ${roses.version} - - - - diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/config/WebSocketConfig.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/config/WebSocketConfig.java deleted file mode 100644 index 89e431033..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/config/WebSocketConfig.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -/** - * 开启WebSocket支持 - * - * @author majianguo - * @since 2021/6/21 下午5:01 - */ -@Configuration -public class WebSocketConfig { - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } -} diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/message/SocketMessageCenter.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/message/SocketMessageCenter.java deleted file mode 100644 index 422f4f015..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/message/SocketMessageCenter.java +++ /dev/null @@ -1,46 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.message; - -import cn.stylefeng.roses.kernel.socket.api.message.SocketMsgCallbackInterface; - -import java.util.HashMap; -import java.util.Map; - -/** - * 会话消息中心 - *

- * 维护所有消息类型对应的处理器 - * - * @author majianguo - * @since 2021/6/1 下午2:20 - */ -public class SocketMessageCenter { - - /** - * 所有消息监听器维护 - */ - private static final Map MESSAGE_LISTENER_MAP = new HashMap<>(); - - /** - * 设置消息类型的监听器 - * - * @param msgType 消息类型 - * @param listener 监听器 - * @author majianguo - * @since 2021/6/1 下午2:25 - **/ - public static void setMessageListener(String msgType, SocketMsgCallbackInterface listener) { - MESSAGE_LISTENER_MAP.put(msgType, listener); - } - - /** - * 获取消息监听器 - * - * @param msgType 消息类型 - * @return {@link SocketMsgCallbackInterface} - * @author majianguo - * @since 2021/6/1 下午2:26 - **/ - public static SocketMsgCallbackInterface getSocketMsgCallbackInterface(String msgType) { - return MESSAGE_LISTENER_MAP.get(msgType); - } -} 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 deleted file mode 100644 index cdb25153c..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/WebSocketOperator.java +++ /dev/null @@ -1,80 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.operator; - -import cn.hutool.core.util.ObjectUtil; -import cn.stylefeng.roses.kernel.socket.api.SocketOperatorApi; -import cn.stylefeng.roses.kernel.socket.api.exception.SocketException; -import cn.stylefeng.roses.kernel.socket.api.exception.enums.SocketExceptionEnum; -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.pojo.WebSocketMessageDTO; -import cn.stylefeng.roses.kernel.socket.business.websocket.session.SessionCenter; -import cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel.GunsSocketOperator; - -import java.util.Collection; -import java.util.List; - -/** - * WebSocket操作实现类 - *

- * 如果是Spring boot项目,通过注入SocketOperatorApi接口操作socket,需将本来交给Spring管理 - * - * @author majianguo - * @since 2021/6/2 上午10:41 - */ -public class WebSocketOperator implements SocketOperatorApi { - - @Override - public void sendMsgOfUserSessionBySessionId(String msgType, String sessionId, Object msg) throws SocketException { - SocketSession session = SessionCenter.getSessionBySessionId(sessionId); - if (ObjectUtil.isEmpty(session)) { - throw new SocketException(SocketExceptionEnum.SESSION_NOT_EXIST); - } - WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO(); - webSocketMessageDTO.setData(msg); - webSocketMessageDTO.setServerMsgType(msgType); - session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO); - } - - @Override - public void sendMsgOfUserSession(String msgType, String userId, Object msg) throws SocketException { - // 根据用户ID获取会话 - 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) { - // 发送内容 - session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO); - } - } - - @Override - public void sendMsgOfAllUserSession(String msgType, Object msg) { - Collection>> values = SessionCenter.getSocketSessionMap().values(); - WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO(); - webSocketMessageDTO.setData(msg); - webSocketMessageDTO.setServerMsgType(msgType); - for (List> sessions : values) { - for (SocketSession session : sessions) { - // 找到该类型的通道 - if (session.getMessageType().equals(msgType)) { - session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO); - } - } - } - } - - @Override - public void closeSocketBySocketId(String socketId) { - SessionCenter.closed(socketId); - } - - @Override - public void msgTypeCallback(String msgType, SocketMsgCallbackInterface callbackInterface) { - SocketMessageCenter.setMessageListener(msgType, callbackInterface); - } -} diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java deleted file mode 100644 index 2fefa994f..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/GunsSocketOperator.java +++ /dev/null @@ -1,59 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel; - -import com.alibaba.fastjson.JSON; -import javax.websocket.Session; -import java.io.IOException; - -/** - * Socket操作类实现 - *

- * 简单封装Spring Boot的默认WebSocket - * - * @author majianguo - * @since 2021/6/1 下午3:41 - */ -public class GunsSocketOperator implements SocketChannelExpandInterFace { - - /** - * 实际操作的通道 - */ - private Session socketChannel; - - public GunsSocketOperator(Session socketChannel) { - this.socketChannel = socketChannel; - } - - @Override - public void writeAndFlush(Object obj) { - try { - if (socketChannel.isOpen()) { - socketChannel.getBasicRemote().sendText(JSON.toJSONString(obj)); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public void writeToChannel(Object obj) { - if (socketChannel.isOpen()) { - socketChannel.getAsyncRemote().sendText(JSON.toJSONString(obj)); - } - } - - @Override - public void close() { - try { - if (socketChannel.isOpen()) { - socketChannel.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public boolean isInvalid() { - return socketChannel.isOpen(); - } -} diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java deleted file mode 100644 index 35f204013..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/operator/channel/SocketChannelExpandInterFace.java +++ /dev/null @@ -1,15 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.operator.channel; - -import cn.stylefeng.roses.kernel.socket.api.session.SocketSessionOperatorApi; - -/** - * 对Api模块的操作类进行扩展 - *

- * 暂时只写接口,SocketOperatorApi方法不够用时再对此类进行扩展 - * - * @author majianguo - * @since 2021/6/1 下午3:44 - */ -public interface SocketChannelExpandInterFace extends SocketSessionOperatorApi { - -} diff --git a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java b/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java deleted file mode 100644 index fd06db094..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/pojo/WebSocketMessageDTO.java +++ /dev/null @@ -1,48 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.pojo; - -import cn.stylefeng.roses.kernel.socket.api.SocketOperatorApi; -import lombok.Data; - -/** - * WebSocket交互通用对象 - *

- * 特殊说明一下serverMsgType和clientMsgType的区别 - * 1.serverMsgType字段是服务端发送给客户端的字段 - * 例如:服务端发送一个系统消息(type:100001),客户端接收到该消息以后判断需不需要处理,不需要处理跳过即可 - *

- * 2.clientMsgType字段是客户端发送给服务器的字段 - * 例如:客户端发送给服务器一个心跳消息(type:299999),服务端如果需要处理该消息就注册一个该消息的监听器, - * 那么收到消息服务端会把消息推送给对应的监听器,接口见{@link SocketOperatorApi#msgTypeCallback} - * - * @author majianguo - * @since 2021/6/1 下午2:56 - */ -@Data -public class WebSocketMessageDTO { - - /** - * 服务端发送的消息类型(客户端如果需要监听该消息类型,注册对应的消息处理器即可) - */ - private String serverMsgType; - - /** - * 客户端发送的消息类型(服务端需要处理的消息类型) - */ - private String clientMsgType; - - /** - * 目标Id - */ - private String toUserId; - - /** - * 发送者ID - */ - private String formUserId; - - /** - * 具体发送的数据 - */ - private Object data; - -} 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 deleted file mode 100644 index 8a0428cf9..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/server/WebSocketServer.java +++ /dev/null @@ -1,182 +0,0 @@ -package cn.stylefeng.roses.kernel.socket.business.websocket.server; - -import cn.hutool.core.util.ObjectUtil; -import cn.stylefeng.roses.kernel.auth.api.context.AuthJwtContext; -import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload; -import cn.stylefeng.roses.kernel.socket.api.enums.ClientMessageTypeEnum; -import cn.stylefeng.roses.kernel.socket.api.enums.ServerMessageTypeEnum; -import cn.stylefeng.roses.kernel.socket.api.enums.SystemMessageTypeEnum; -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.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; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import javax.websocket.*; -import javax.websocket.server.PathParam; -import javax.websocket.server.ServerEndpoint; -import java.io.IOException; - -/** - * 消息监听处理器 - * - * @author majianguo - * @since 2021/6/1 下午2:35 - */ -@Slf4j -@ServerEndpoint(value = "/webSocket/{token}") -@Component -public class WebSocketServer { - - /** - * 连接建立调用的方法 - *

- * 暂时无用,需要在建立连接的时候做一些事情的话可以修改这里 - * - * @param session 会话信息 - * @author majianguo - * @since 2021/6/21 下午5:14 - **/ - @OnOpen - public void onOpen(Session session, @PathParam("token") String token) { - String userId = null; - try { - // 解析用户信息 - DefaultJwtPayload defaultPayload = AuthJwtContext.me().getDefaultPayload(token); - userId = defaultPayload.getUserId().toString(); - } catch (io.jsonwebtoken.JwtException e) { - try { - session.close(); - } catch (IOException ioException) { - ioException.printStackTrace(); - } - } - - // 操作api包装 - GunsSocketOperator gunsSocketOperator = new GunsSocketOperator(session); - - // 回复消息 - WebSocketMessageDTO replyMsg = new WebSocketMessageDTO(); - replyMsg.setServerMsgType(ServerMessageTypeEnum.SYS_REPLY_MSG_TYPE.getCode()); - replyMsg.setToUserId(userId); - - // 创建会话对象 - SocketSession socketSession = new SocketSession<>(); - try { - // 设置回复内容 - replyMsg.setData(session.getId()); - socketSession.setSessionId(session.getId()); - socketSession.setUserId(userId); - socketSession.setSocketOperatorApi(gunsSocketOperator); - socketSession.setToken(token); - socketSession.setConnectionTime(System.currentTimeMillis()); - - // 维护会话 - SessionCenter.addSocketSession(socketSession); - } finally { - // 回复消息 - gunsSocketOperator.writeAndFlush(replyMsg); - - // 触发首次连接回调 - SocketMsgCallbackInterface socketMsgCallbackInterface = SocketMessageCenter.getSocketMsgCallbackInterface(SystemMessageTypeEnum.SYS_LISTENER_ONOPEN.getCode()); - if (ObjectUtil.isNotEmpty(socketMsgCallbackInterface)) { - // 触发回调 - socketMsgCallbackInterface.callback(SystemMessageTypeEnum.SYS_LISTENER_ONOPEN.getCode(), null, socketSession); - } - } - - } - - /** - * 连接关闭调用的方法 - * - * @param session 会话信息 - * @author majianguo - * @since 2021/6/21 下午5:14 - **/ - @OnClose - public void onClose(Session session) { - try { - SocketSession socketSession = SessionCenter.getSessionBySessionId(session.getId()); - // 触发首次连接回调 - SocketMsgCallbackInterface socketMsgCallbackInterface = SocketMessageCenter.getSocketMsgCallbackInterface(SystemMessageTypeEnum.SYS_LISTENER_ONCLOSE.getCode()); - if (ObjectUtil.isNotEmpty(socketSession) && ObjectUtil.isNotEmpty(socketMsgCallbackInterface)) { - // 触发回调 - socketMsgCallbackInterface.callback(SystemMessageTypeEnum.SYS_LISTENER_ONCLOSE.getCode(), null, socketSession); - } - } finally { - SessionCenter.deleteById(session.getId()); - } - } - - /** - * 收到消息调用的方法 - * - * @param message  接收到的消息 - * @param socketChannel 会话信息 - * @author majianguo - * @since 2021/6/21 下午5:14 - **/ - @OnMessage - public void onMessage(String message, Session socketChannel) { - - // 转换为Java对象 - WebSocketMessageDTO WebSocketMessageDTO = JSON.parseObject(message, WebSocketMessageDTO.class); - - // 维护通道是否已初始化 - SocketSession socketSession = SessionCenter.getSessionBySessionId(socketChannel.getId()); - - // 心跳包 - if (ObjectUtil.isNotEmpty(socketSession) && ClientMessageTypeEnum.USER_HEART.getCode().equals(WebSocketMessageDTO.getClientMsgType())) { - // 更新会话最后活跃时间 - if (ObjectUtil.isNotEmpty(socketSession)) { - socketSession.setLastActiveTime(System.currentTimeMillis()); - } - return; - } - - // 用户ID为空不处理直接跳过 - if (ObjectUtil.isEmpty(WebSocketMessageDTO.getFormUserId())) { - return; - } - - // 会话建立成功执行业务逻辑 - if (ObjectUtil.isNotEmpty(socketSession)) { - - // 更新最后会话时间 - socketSession.setLastActiveTime(System.currentTimeMillis()); - - // 找到该消息的处理器 - SocketMsgCallbackInterface socketMsgCallbackInterface = SocketMessageCenter.getSocketMsgCallbackInterface(WebSocketMessageDTO.getClientMsgType()); - if (ObjectUtil.isNotEmpty(socketMsgCallbackInterface)) { - // 触发回调 - socketMsgCallbackInterface.callback(WebSocketMessageDTO.getClientMsgType(), WebSocketMessageDTO, socketSession); - } else { - socketChannel.getAsyncRemote().sendText("{\"serverMsgType\":\"404\"}"); - } - } - } - - /** - * 会话发送异常调用的方法 - * - * @param session 会话信息 - * @param error  错误信息 - * @author majianguo - * @since 2021/6/21 下午5:14 - **/ - @OnError - public void onError(Session session, Throwable error) { - SocketSession socketSession = SessionCenter.getSessionBySessionId(session.getId()); - // 触发首次连接回调 - SocketMsgCallbackInterface socketMsgCallbackInterface = SocketMessageCenter.getSocketMsgCallbackInterface(SystemMessageTypeEnum.SYS_LISTENER_ONERROR.getCode()); - if (ObjectUtil.isNotEmpty(socketMsgCallbackInterface)) { - // 触发回调 - socketMsgCallbackInterface.callback(SystemMessageTypeEnum.SYS_LISTENER_ONERROR.getCode(), error, socketSession); - } - } -} 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 deleted file mode 100644 index dc682072f..000000000 --- a/kernel-d-socket/socket-business-websocket/src/main/java/cn/stylefeng/roses/kernel/socket/business/websocket/session/SessionCenter.java +++ /dev/null @@ -1,145 +0,0 @@ -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.GunsSocketOperator; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * 会话中心 - *

- * 维护所有的会话 - * - * @author majianguo - * @since 2021/6/1 下午1:43 - */ -public class SessionCenter { - - /** - * 所有用户会话维护 - */ - private static ConcurrentMap>> socketSessionMap = new ConcurrentHashMap<>(); - - /** - * 获取维护的所有会话 - * - * @return {@link ConcurrentMap< String, SocketSession>} - * @author majianguo - * @since 2021/6/1 下午2:13 - **/ - public static ConcurrentMap>> getSocketSessionMap() { - return socketSessionMap; - } - - /** - * 根据用户ID获取会话信息列表 - * - * @param userId 用户ID - * @return {@link SocketSession } - * @author majianguo - * @since 2021/6/1 下午1:48 - **/ - public static List> getSessionByUserId(String userId) { - return socketSessionMap.get(userId); - } - - /** - * 根据用户ID和消息类型获取会话信息列表 - * - * @param userId 用户ID - * @return {@link SocketSession } - * @author majianguo - * @since 2021/6/1 下午1:48 - **/ - public static List> getSessionByUserIdAndMsgType(String userId) { - return socketSessionMap.get(userId); - } - - /** - * 根据会话ID获取会话信息 - * - * @param sessionId 会话ID - * @return {@link SocketSession } - * @author majianguo - * @since 2021/6/1 下午1:48 - **/ - public static SocketSession getSessionBySessionId(String sessionId) { - Set>>> entrySet = socketSessionMap.entrySet(); - for (Map.Entry>> stringListEntry : entrySet) { - List> stringListEntryValue = stringListEntry.getValue(); - for (SocketSession socketSession : stringListEntryValue) { - if (sessionId.equals(socketSession.getSessionId())) { - return socketSession; - } - } - } - return null; - } - - /** - * 设置会话 - * - * @param socketSession 会话详情 - * @author majianguo - * @since 2021/6/1 下午1:49 - **/ - public static void addSocketSession(SocketSession socketSession) { - List> socketSessions = socketSessionMap.get(socketSession.getUserId()); - if (ObjectUtil.isEmpty(socketSessions)) { - socketSessions = Collections.synchronizedList(new ArrayList<>()); - socketSessionMap.put(socketSession.getUserId(), socketSessions); - } - socketSessions.add(socketSession); - } - - /** - * 连接关闭 - * - * @param sessionId 会话ID - * @author majianguo - * @since 2021/6/1 下午3:25 - **/ - public static void closed(String sessionId) { - // 删除维护关系 - SocketSession operatorSocketSession = getSessionBySessionId(sessionId); - if (ObjectUtil.isNotEmpty(operatorSocketSession)) { - operatorSocketSession.getSocketOperatorApi().close(); - } - } - - /** - * 删除维护关系 - * - * @param sessionId 会话ID - * @return {@link cn.stylefeng.roses.kernel.socket.api.session.pojo.SocketSession} - * @author majianguo - * @since 2021/8/30 9:20 - **/ - public static SocketSession deleteById(String sessionId) { - // 获取所有人员的连接会话信息 - Set>>> entrySet = socketSessionMap.entrySet(); - Iterator>>> iterator = entrySet.iterator(); - while (iterator.hasNext()) { - Map.Entry>> next = iterator.next(); - List> value = next.getValue(); - if (ObjectUtil.isNotEmpty(value)) { - - // 找出该人员的指定会话信息 - Iterator> socketSessionIterator = value.iterator(); - while (socketSessionIterator.hasNext()) { - SocketSession operatorSocketSession = socketSessionIterator.next(); - if (operatorSocketSession.getSessionId().equals(sessionId)) { - // 在列表中删除 - socketSessionIterator.remove(); - return operatorSocketSession; - } - } - } - } - - return null; - } -} diff --git a/kernel-d-socket/socket-spring-boot-starter/README.md b/kernel-d-socket/socket-spring-boot-starter/README.md deleted file mode 100644 index 706e2efc9..000000000 --- a/kernel-d-socket/socket-spring-boot-starter/README.md +++ /dev/null @@ -1 +0,0 @@ -Socket的spring boot自动加载模块 \ No newline at end of file diff --git a/kernel-d-socket/socket-spring-boot-starter/pom.xml b/kernel-d-socket/socket-spring-boot-starter/pom.xml deleted file mode 100644 index 89e621fab..000000000 --- a/kernel-d-socket/socket-spring-boot-starter/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - - - cn.stylefeng.roses - kernel-d-socket - 8.1.0 - ../pom.xml - - - socket-spring-boot-starter - - jar - - - - - - cn.stylefeng.roses - socket-business-websocket - ${roses.version} - - - - - diff --git a/kernel-d-socket/socket-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/socket/starter/ProjectSocketAutoConfiguration.java b/kernel-d-socket/socket-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/socket/starter/ProjectSocketAutoConfiguration.java deleted file mode 100644 index 29e02d91a..000000000 --- a/kernel-d-socket/socket-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/socket/starter/ProjectSocketAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright [2020-2030] [https://www.stylefeng.cn] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - * - * 1.请不要删除和修改根目录下的LICENSE文件。 - * 2.请不要删除和修改Guns源码头部的版权声明。 - * 3.请保留源码和相关描述文件的项目出处,作者声明等。 - * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns - * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns - * 6.若您的项目无法满足以上几点,可申请商业授权 - */ -package cn.stylefeng.roses.kernel.socket.starter; - -import cn.stylefeng.roses.kernel.socket.api.SocketOperatorApi; -import cn.stylefeng.roses.kernel.socket.business.websocket.operator.WebSocketOperator; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Socket的自动配置类 - * - * @author majianguo - * @since 2021/6/2 下午5:48 - */ -@Configuration -public class ProjectSocketAutoConfiguration { - - /** - * Socket操作实现类 - * - * @author majianguo - * @since 2021/6/2 下午5:48 - **/ - @Bean - @ConditionalOnMissingBean(SocketOperatorApi.class) - public SocketOperatorApi socketOperatorApi() { - return new WebSocketOperator(); - } - -} diff --git a/kernel-d-socket/socket-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-d-socket/socket-spring-boot-starter/src/main/resources/META-INF/spring.factories deleted file mode 100644 index f1937d9c0..000000000 --- a/kernel-d-socket/socket-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - cn.stylefeng.roses.kernel.socket.starter.ProjectSocketAutoConfiguration \ No newline at end of file diff --git a/kernel-s-system/system-spring-boot-starter/pom.xml b/kernel-s-system/system-spring-boot-starter/pom.xml index 10afc811b..ed2277bea 100644 --- a/kernel-s-system/system-spring-boot-starter/pom.xml +++ b/kernel-s-system/system-spring-boot-starter/pom.xml @@ -117,13 +117,6 @@ ${roses.version} - - - cn.stylefeng.roses - socket-spring-boot-starter - ${roses.version} - - cn.stylefeng.roses diff --git a/pom.xml b/pom.xml index 5c1119ee9..c7cefda9c 100644 --- a/pom.xml +++ b/pom.xml @@ -73,9 +73,6 @@ kernel-d-sms - - kernel-d-socket - kernel-d-timer