Skip to content

Commit f34ecef

Browse files
committed
替换SimpleChannelInboundHandler
1 parent 924b3de commit f34ecef

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/main/java/love/wangqi/filter/command/HttpClientPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private HttpClientPool() {
4646
@Override
4747
protected SimpleChannelPool newPool(RequestHolder requestHolder) {
4848
logger.debug("address: {}", requestHolder.getSocketAddress());
49-
return new FixedChannelPool(bootstrap.remoteAddress(requestHolder.getSocketAddress()), new HttpPoolHandler(requestHolder), 1);
49+
return new FixedChannelPool(bootstrap.remoteAddress(requestHolder.getSocketAddress()), new HttpPoolHandler(requestHolder), 50);
5050
}
5151
};
5252
}

src/main/java/love/wangqi/filter/command/HttpHandler.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.netty.channel.Channel;
44
import io.netty.channel.ChannelHandlerContext;
5-
import io.netty.channel.ChannelInboundHandlerAdapter;
65
import io.netty.channel.SimpleChannelInboundHandler;
76
import io.netty.handler.codec.http.FullHttpResponse;
87
import io.netty.handler.timeout.ReadTimeoutException;
@@ -16,20 +15,17 @@
1615
/**
1716
* @author: wangqi
1817
* @description:
19-
* @date: Created in 2018-11-26 20:59
18+
* @date: Created in 2018-11-28 08:37
2019
*/
21-
public class HttpHandler extends ChannelInboundHandlerAdapter {
20+
public class HttpHandler extends SimpleChannelInboundHandler<FullHttpResponse> {
2221
private Logger logger = LoggerFactory.getLogger(HttpHandler.class);
2322

24-
@Override
25-
public void channelActive(ChannelHandlerContext ctx) throws Exception {
26-
System.out.println("channelActive");
27-
super.channelActive(ctx);
23+
public HttpHandler() {
24+
super(false);
2825
}
2926

3027
@Override
31-
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
32-
FullHttpResponse response = (FullHttpResponse) msg;
28+
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) throws Exception {
3329
logger.debug("handler hashCode: {}", this.hashCode());
3430
logger.debug("clientChannelId: {}", ctx.channel().id());
3531
Channel serverChannel = ctx.channel().attr(Attributes.SERVER_CHANNEL).get();
@@ -40,6 +36,12 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
4036
GatewayRunner.getInstance().postRoutAction(serverChannel);
4137
}
4238

39+
@Override
40+
public void channelActive(ChannelHandlerContext ctx) throws Exception {
41+
System.out.println("channelActive");
42+
super.channelActive(ctx);
43+
}
44+
4345
@Override
4446
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
4547
Channel serverChannel = ctx.channel().attr(Attributes.SERVER_CHANNEL).get();

src/main/java/love/wangqi/filter/command/HttpPoolHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
import io.netty.handler.ssl.SslContextBuilder;
1212
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
1313
import io.netty.handler.stream.ChunkedWriteHandler;
14-
import io.netty.handler.timeout.ReadTimeoutHandler;
1514
import love.wangqi.codec.RequestHolder;
1615
import org.slf4j.Logger;
1716
import org.slf4j.LoggerFactory;
1817

1918
import javax.net.ssl.SSLException;
2019

21-
import java.util.concurrent.TimeUnit;
22-
2320
import static love.wangqi.context.Constants.HTTPS;
2421

2522
/**

0 commit comments

Comments
 (0)