【fix】 使用线程池处理流量信息及业务

This commit is contained in:
wujiawei
2024-09-03 16:37:46 +08:00
parent 58aae7a67d
commit b9d75715de
13 changed files with 141 additions and 31 deletions

View File

@ -46,7 +46,6 @@ public class ServerHandleReportHandleChannelTransferTypeAdvanced extends Abstrac
ByteBuf buf = visitor.config().getAllocator().buffer(msg.getData().length);
buf.writeBytes(msg.getData());
visitor.writeAndFlush(buf);
log.info("writeAndFlush");
// 记录出口数据
ServerChannelFlow serverChannelFlow = ServerChannelFlow
.builder()
@ -55,7 +54,7 @@ public class ServerHandleReportHandleChannelTransferTypeAdvanced extends Abstrac
.clientId(clientId)
.flow(msg.getData().length)
.build();
channelFlowAdapter.handler(channel, serverChannelFlow);
channelFlowAdapter.asyncHandler(channel, serverChannelFlow);
}
}

View File

@ -44,13 +44,11 @@ public class ServerHandlerInFlowHandler extends AbstractHandleChannelFlowAdvance
Integer flow = channelFlow.flow();
// 进口流量处理
if (serverNodeProperties.getEnableFlowControl()) {
LazyVisitorPortFlowStoryCommand visitorPortFlow = new LazyVisitorPortFlowStoryCommand();
visitorPortFlow.setInFlow(flow);
visitorPortFlow.setClientId(clientId);
visitorPortFlow.setVisitorPort(port);
visitorPortFlow.setIsDeleted(false);
lazyVisitorPortFlowApplication.flowIncreaseStory(visitorPortFlow);
}
LazyVisitorPortFlowStoryCommand visitorPortFlow = new LazyVisitorPortFlowStoryCommand();
visitorPortFlow.setInFlow(flow);
visitorPortFlow.setClientId(clientId);
visitorPortFlow.setVisitorPort(port);
visitorPortFlow.setIsDeleted(false);
lazyVisitorPortFlowApplication.flowIncreaseStory(visitorPortFlow);
}
}

View File

@ -44,14 +44,12 @@ public class ServerHandlerOutFlowHandler extends AbstractHandleChannelFlowAdvanc
Integer flow = channelFlow.flow();
// 出口流量处理
LazyVisitorPortFlowStoryCommand visitorPortFlow = new LazyVisitorPortFlowStoryCommand();
visitorPortFlow.setOutFlow(flow);
visitorPortFlow.setClientId(clientId);
visitorPortFlow.setVisitorPort(port);
visitorPortFlow.setIsDeleted(false);
lazyVisitorPortFlowApplication.flowIncreaseStory(visitorPortFlow);
if(serverNodeProperties.getEnableFlowControl()){
LazyVisitorPortFlowStoryCommand visitorPortFlow = new LazyVisitorPortFlowStoryCommand();
visitorPortFlow.setOutFlow(flow);
visitorPortFlow.setClientId(clientId);
visitorPortFlow.setVisitorPort(port);
visitorPortFlow.setIsDeleted(false);
lazyVisitorPortFlowApplication.flowIncreaseStory(visitorPortFlow);
}
}
}

View File

@ -20,6 +20,7 @@ import java.util.UUID;
public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
private final InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient;
private final ChannelFlowAdapter channelFlowAdapter;// 流量适配器
// private final NettyChannelPool nettyChannelPool = new DefaultNettyChannelPool(10);
public VisitorHandler(InternalNetworkPenetrationRealClient internalNetworkPenetrationRealClient, ChannelFlowAdapter channelFlowAdapter) {
this.internalNetworkPenetrationRealClient = internalNetworkPenetrationRealClient;
@ -55,8 +56,8 @@ public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
nettyProxyMsg.setVisitorId(visitorId);
// 判断是否有可用的通道 如果没有创建新的通道
// Channel transferChannel = nettyChannelPool.availableChannel(visitorId);
// if (transferChannel == null) {
// 客户端心跳通道
ChannelContext.ClientChannel clientChannel = ChannelContext.get(clientId);
if (clientChannel != null) {
@ -66,7 +67,7 @@ public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
} else {
log.error("客户端:【{}】已经下线无法通过客户端ID获取客户端通道", clientId);
}
// }
// 等待访客ID传输到客户端后绑定客户端真实服务后开启
@ -114,7 +115,7 @@ public class VisitorHandler extends SimpleChannelInboundHandler<ByteBuf> {
.clientId(clientId)
.flow(bytes.length)
.build();
channelFlowAdapter.handler(visitorChannel, serverChannelFlow);
channelFlowAdapter.asyncHandler(visitorChannel, serverChannelFlow);
log.debug("服务端访客端口成功发送数据了");
}