部分代码优化

This commit is contained in:
aoshiguchen
2022-10-23 13:53:54 +08:00
parent f71055b6ea
commit 4b8ec0b33b
5 changed files with 10 additions and 11 deletions
@@ -49,7 +49,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
} else {
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
String visitorId = ProxyUtil.getRealServerChannelVisitorId(realServerChannel);
String visitorId = ProxyUtil.getVisitorIdByRealServerChannel(realServerChannel);
channel.writeAndFlush(ProxyMessage.buildTransferMessage(visitorId, bytes));
}
}
@@ -62,7 +62,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
Channel realServerChannel = ctx.channel();
String visitorId = ProxyUtil.getRealServerChannelVisitorId(realServerChannel);
String visitorId = ProxyUtil.getVisitorIdByRealServerChannel(realServerChannel);
ProxyUtil.removeRealServerChannel(visitorId);
Channel channel = realServerChannel.attr(Constants.NEXT_CHANNEL).get();
if (channel != null) {
@@ -101,7 +101,7 @@ public class ProxyUtil {
realServerChannel.attr(Constants.VISITOR_ID).set(visitorId);
}
public static String getRealServerChannelVisitorId(Channel realServerChannel) {
public static String getVisitorIdByRealServerChannel(Channel realServerChannel) {
return realServerChannel.attr(Constants.VISITOR_ID).get();
}
@@ -27,7 +27,6 @@ import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Arrays;
import java.util.List;
/**
*
@@ -125,9 +124,9 @@ public class ProxyMessage {
.setInfo(info);
}
public static ProxyMessage buildTransferMessage(String info, byte[] data) {
public static ProxyMessage buildTransferMessage(String visitorId, byte[] data) {
return create().setType(TYPE_TRANSFER)
.setInfo(info)
.setInfo(visitorId)
.setData(data);
}
@@ -63,8 +63,8 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
} else {
byte[] bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
String userId = ProxyUtil.getVisitorChannelUserId(visitorChannel);
proxyChannel.writeAndFlush(ProxyMessage.buildTransferMessage(userId, bytes));
String visitorId = ProxyUtil.getVisitorIdByChannel(visitorChannel);
proxyChannel.writeAndFlush(ProxyMessage.buildTransferMessage(visitorId, bytes));
}
}
@@ -104,7 +104,7 @@ public class VisitorChannelHandler extends SimpleChannelInboundHandler<ByteBuf>
} else {
// 用户连接断开,从控制连接中移除
String userId = ProxyUtil.getVisitorChannelUserId(userChannel);
String userId = ProxyUtil.getVisitorIdByChannel(userChannel);
ProxyUtil.removeVisitorChannelFromCmdChannel(cmdChannel, userId);
Channel proxyChannel = userChannel.attr(Constants.NEXT_CHANNEL).get();
@@ -217,12 +217,12 @@ public class ProxyUtil {
}
/**
* 获取用户编号
* 获取访问者ID
*
* @param visitorChannel
* @return
*/
public static String getVisitorChannelUserId(Channel visitorChannel) {
public static String getVisitorIdByChannel(Channel visitorChannel) {
if (null == visitorChannel || null == getAttachInfo(visitorChannel)) {
return null;
}