import org.slf4j.LoggerFactory;
public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(ProxyServerHandler.class.getName());
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyServerHandler.class);
private final Bootstrap clientBootstrap;
private final LocalAddress localAddress;
@Override
public void channelInactive(ChannelHandlerContext ctx) {
- logger.trace("channelInactive - closing client channel");
+ LOG.trace("channelInactive - closing client channel");
clientChannel.close();
}
@Override
public void channelRead(ChannelHandlerContext ctx, final Object msg) {
- logger.trace("Writing to client channel");
+ LOG.trace("Writing to client channel");
clientChannel.write(msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
- logger.trace("Flushing client channel");
+ LOG.trace("Flushing client channel");
clientChannel.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
- logger.warn("Unexpected exception from downstream.", cause);
+ LOG.warn("Unexpected exception from downstream.", cause);
ctx.close();
}
}
class ProxyClientHandler extends ChannelInboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(ProxyClientHandler.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyClientHandler.class);
private final ChannelHandlerContext remoteCtx;
private ChannelHandlerContext localCtx;
@Override
public void channelActive(ChannelHandlerContext ctx) {
checkState(this.localCtx == null);
- logger.trace("Client channel active");
+ LOG.trace("Client channel active");
this.localCtx = ctx;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- logger.trace("Forwarding message");
+ LOG.trace("Forwarding message");
remoteCtx.write(msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
- logger.trace("Flushing remote ctx");
+ LOG.trace("Flushing remote ctx");
remoteCtx.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
- logger.warn("Unexpected exception from downstream", cause);
+ LOG.warn("Unexpected exception from downstream", cause);
checkState(this.localCtx.equals(ctx));
ctx.close();
}
// called both when local or remote connection dies
@Override
public void channelInactive(ChannelHandlerContext ctx) {
- logger.trace("channelInactive() called, closing remote client ctx");
+ LOG.trace("channelInactive() called, closing remote client ctx");
remoteCtx.close();
}