修改日志变量

master
星期八 5 years ago
parent 7e3b699aae
commit 26aabc7ccf
  1. 24
      proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java
  2. 8
      proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/RealServerChannelHandler.java

@ -26,12 +26,18 @@ import io.netty.channel.SimpleChannelInboundHandler;
*/ */
public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> { public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessage> {
private static Logger logger = LoggerFactory.getLogger(ClientChannelHandler.class); private static Logger LOGGER = LoggerFactory.getLogger(ClientChannelHandler.class);
/**
* 引导器
*/
private Bootstrap bootstrap; private Bootstrap bootstrap;
/**
* 代理引导器
*/
private Bootstrap proxyBootstrap; private Bootstrap proxyBootstrap;
/**
* 管道状态监听
*/
private ChannelStatusListener channelStatusListener; private ChannelStatusListener channelStatusListener;
public ClientChannelHandler(Bootstrap bootstrap, Bootstrap proxyBootstrap, ChannelStatusListener channelStatusListener) { public ClientChannelHandler(Bootstrap bootstrap, Bootstrap proxyBootstrap, ChannelStatusListener channelStatusListener) {
@ -42,7 +48,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, ProxyMessage proxyMessage) throws Exception {
logger.debug("recieved proxy message, type is {}", proxyMessage.getType()); LOGGER.debug("recieved proxy message, type is {}", proxyMessage.getType());
switch (proxyMessage.getType()) { switch (proxyMessage.getType()) {
case ProxyMessage.TYPE_CONNECT: case ProxyMessage.TYPE_CONNECT:
handleConnectMessage(ctx, proxyMessage); handleConnectMessage(ctx, proxyMessage);
@ -63,14 +69,14 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
if (realServerChannel != null) { if (realServerChannel != null) {
ByteBuf buf = ctx.alloc().buffer(proxyMessage.getData().length); ByteBuf buf = ctx.alloc().buffer(proxyMessage.getData().length);
buf.writeBytes(proxyMessage.getData()); buf.writeBytes(proxyMessage.getData());
logger.debug("write data to real server, {}", realServerChannel); LOGGER.debug("write data to real server, {}", realServerChannel);
realServerChannel.writeAndFlush(buf); realServerChannel.writeAndFlush(buf);
} }
} }
private void handleDisconnectMessage(ChannelHandlerContext ctx, ProxyMessage proxyMessage) { private void handleDisconnectMessage(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get(); Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
logger.debug("handleDisconnectMessage, {}", realServerChannel); LOGGER.debug("handleDisconnectMessage, {}", realServerChannel);
if (realServerChannel != null) { if (realServerChannel != null) {
ctx.channel().attr(Constants.NEXT_CHANNEL).set(null); ctx.channel().attr(Constants.NEXT_CHANNEL).set(null);
ClientChannelMannager.returnProxyChanel(ctx.channel()); ClientChannelMannager.returnProxyChanel(ctx.channel());
@ -92,7 +98,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
// 连接后端服务器成功 // 连接后端服务器成功
if (future.isSuccess()) { if (future.isSuccess()) {
final Channel realServerChannel = future.channel(); final Channel realServerChannel = future.channel();
logger.debug("connect realserver success, {}", realServerChannel); LOGGER.debug("connect realserver success, {}", realServerChannel);
realServerChannel.config().setOption(ChannelOption.AUTO_READ, false); realServerChannel.config().setOption(ChannelOption.AUTO_READ, false);
@ -167,7 +173,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error("exception caught", cause); LOGGER.error("exception caught", cause);
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }

@ -17,7 +17,7 @@ import io.netty.channel.SimpleChannelInboundHandler;
*/ */
public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBuf> { public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
private static Logger logger = LoggerFactory.getLogger(RealServerChannelHandler.class); private static Logger LOGGER = LoggerFactory.getLogger(RealServerChannelHandler.class);
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
@ -35,7 +35,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
proxyMessage.setUri(userId); proxyMessage.setUri(userId);
proxyMessage.setData(bytes); proxyMessage.setData(bytes);
channel.writeAndFlush(proxyMessage); channel.writeAndFlush(proxyMessage);
logger.debug("write data to proxy server, {}, {}", realServerChannel, channel); LOGGER.debug("write data to proxy server, {}, {}", realServerChannel, channel);
} }
} }
@ -51,7 +51,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
ClientChannelMannager.removeRealServerChannel(userId); ClientChannelMannager.removeRealServerChannel(userId);
Channel channel = realServerChannel.attr(Constants.NEXT_CHANNEL).get(); Channel channel = realServerChannel.attr(Constants.NEXT_CHANNEL).get();
if (channel != null) { if (channel != null) {
logger.debug("channelInactive, {}", realServerChannel); LOGGER.debug("channelInactive, {}", realServerChannel);
ProxyMessage proxyMessage = new ProxyMessage(); ProxyMessage proxyMessage = new ProxyMessage();
proxyMessage.setType(ProxyMessage.TYPE_DISCONNECT); proxyMessage.setType(ProxyMessage.TYPE_DISCONNECT);
proxyMessage.setUri(userId); proxyMessage.setUri(userId);
@ -74,7 +74,7 @@ public class RealServerChannelHandler extends SimpleChannelInboundHandler<ByteBu
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error("exception caught", cause); LOGGER.error("exception caught", cause);
super.exceptionCaught(ctx, cause); super.exceptionCaught(ctx, cause);
} }
} }
Loading…
Cancel
Save