1.修改类命名

pull/22/head
rays 2021-06-22 15:46:34 +08:00
parent e6f887294d
commit 439eab3f21
5 changed files with 35 additions and 35 deletions

View File

@ -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<GettySocketOperator> session = SessionCenter.getSessionBySessionId(sessionId);
SocketSession<GunsSocketOperator> 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<SocketSession<GettySocketOperator>> socketSessionList = SessionCenter.getSessionByUserIdAndMsgType(userId);
List<SocketSession<GunsSocketOperator>> 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<GettySocketOperator> session : socketSessionList) {
for (SocketSession<GunsSocketOperator> session : socketSessionList) {
// 发送内容
session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO);
}
@ -54,12 +54,12 @@ public class WebSocketOperator implements SocketOperatorApi {
@Override
public void sendMsgOfAllUserSession(String msgType, Object msg) {
Collection<List<SocketSession<GettySocketOperator>>> values = SessionCenter.getSocketSessionMap().values();
Collection<List<SocketSession<GunsSocketOperator>>> values = SessionCenter.getSocketSessionMap().values();
WebSocketMessageDTO webSocketMessageDTO = new WebSocketMessageDTO();
webSocketMessageDTO.setData(msg);
webSocketMessageDTO.setServerMsgType(msgType);
for (List<SocketSession<GettySocketOperator>> sessions : values) {
for (SocketSession<GettySocketOperator> session : sessions) {
for (List<SocketSession<GunsSocketOperator>> sessions : values) {
for (SocketSession<GunsSocketOperator> session : sessions) {
// 找到该类型的通道
if (session.getMessageType().equals(msgType)) {
session.getSocketOperatorApi().writeAndFlush(webSocketMessageDTO);

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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<GettySocketOperator> socketSession = new SocketSession<>();
SocketSession<GunsSocketOperator> 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<GettySocketOperator> socketSession = SessionCenter.getSessionBySessionId(socketChannel.getId());
SocketSession<GunsSocketOperator> socketSession = SessionCenter.getSessionBySessionId(socketChannel.getId());
// 心跳包
if (ObjectUtil.isNotEmpty(socketSession) && ClientMessageTypeEnum.USER_HEART.getCode().equals(WebSocketMessageDTO.getClientMsgType())) {

View File

@ -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<String, List<SocketSession<GettySocketOperator>>> socketSessionMap = new ConcurrentHashMap<>();
private static ConcurrentMap<String, List<SocketSession<GunsSocketOperator>>> socketSessionMap = new ConcurrentHashMap<>();
/**
*
*
* @return {@link ConcurrentMap< String, SocketSession<GettySocketOperator>>}
* @return {@link ConcurrentMap< String, SocketSession<GunsSocketOperator>>}
* @author majianguo
* @date 2021/6/1 2:13
**/
public static ConcurrentMap<String, List<SocketSession<GettySocketOperator>>> getSocketSessionMap() {
public static ConcurrentMap<String, List<SocketSession<GunsSocketOperator>>> getSocketSessionMap() {
return socketSessionMap;
}
@ -38,11 +38,11 @@ public class SessionCenter {
* ID
*
* @param userId ID
* @return {@link SocketSession <GettySocketOperator>}
* @return {@link SocketSession <GunsSocketOperator>}
* @author majianguo
* @date 2021/6/1 1:48
**/
public static List<SocketSession<GettySocketOperator>> getSessionByUserId(String userId) {
public static List<SocketSession<GunsSocketOperator>> getSessionByUserId(String userId) {
return socketSessionMap.get(userId);
}
@ -50,11 +50,11 @@ public class SessionCenter {
* ID
*
* @param userId ID
* @return {@link SocketSession <GettySocketOperator>}
* @return {@link SocketSession <GunsSocketOperator>}
* @author majianguo
* @date 2021/6/1 1:48
**/
public static List<SocketSession<GettySocketOperator>> getSessionByUserIdAndMsgType(String userId) {
public static List<SocketSession<GunsSocketOperator>> getSessionByUserIdAndMsgType(String userId) {
return socketSessionMap.get(userId);
}
@ -62,13 +62,13 @@ public class SessionCenter {
* ID
*
* @param sessionId ID
* @return {@link SocketSession <GettySocketOperator>}
* @return {@link SocketSession <GunsSocketOperator>}
* @author majianguo
* @date 2021/6/1 1:48
**/
public static SocketSession<GettySocketOperator> getSessionBySessionId(String sessionId) {
for (List<SocketSession<GettySocketOperator>> values : socketSessionMap.values()) {
for (SocketSession<GettySocketOperator> session : values) {
public static SocketSession<GunsSocketOperator> getSessionBySessionId(String sessionId) {
for (List<SocketSession<GunsSocketOperator>> values : socketSessionMap.values()) {
for (SocketSession<GunsSocketOperator> 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<GettySocketOperator> socketSession) {
List<SocketSession<GettySocketOperator>> socketSessions = socketSessionMap.get(socketSession.getUserId());
public static void addSocketSession(SocketSession<GunsSocketOperator> socketSession) {
List<SocketSession<GunsSocketOperator>> 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<Map.Entry<String, List<SocketSession<GettySocketOperator>>>> entrySet = socketSessionMap.entrySet();
Iterator<Map.Entry<String, List<SocketSession<GettySocketOperator>>>> iterator = entrySet.iterator();
Set<Map.Entry<String, List<SocketSession<GunsSocketOperator>>>> entrySet = socketSessionMap.entrySet();
Iterator<Map.Entry<String, List<SocketSession<GunsSocketOperator>>>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Map.Entry<String, List<SocketSession<GettySocketOperator>>> next = iterator.next();
List<SocketSession<GettySocketOperator>> value = next.getValue();
Map.Entry<String, List<SocketSession<GunsSocketOperator>>> next = iterator.next();
List<SocketSession<GunsSocketOperator>> value = next.getValue();
if (ObjectUtil.isNotEmpty(value)) {
value.removeIf(gettySocketOperatorSocketSession -> gettySocketOperatorSocketSession.getSessionId().equals(sessionId));
value.removeIf(GunsSocketOperatorSocketSession -> GunsSocketOperatorSocketSession.getSessionId().equals(sessionId));
}
}
}