gpt4 book ai didi

java - Netty ChannelAcquired 没有被调用

转载 作者:行者123 更新时间:2023-12-01 11:03:38 25 4
gpt4 key购买 nike

我在 http 客户端和 ChannelPoolHandler 中使用 netty channel 池实现channelAcquiredchannelPool.acquire() 时没有被调用调用。我正在使用 netty 4.0.32.Final 。这是我创建chanelpool的方法。我只是按照 netty.io 上列出的简单示例进行操作。如果有人可以解释我做错了什么或者是否存在错误,那将非常有帮助。谢谢。

EventLoopGroup group = new NioEventLoopGroup();
final Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class);
AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool> poolMap = new AbstractChannelPoolMap<InetSocketAddress, SimpleChannelPool>() {
@Override
protected SimpleChannelPool newPool(InetSocketAddress key) {
return new SimpleChannelPool(b.remoteAddress(key), new HttpClientPoolHandler());
}
};

final SimpleChannelPool simpleChannelPool = poolMap.get(new InetSocketAddress(uri.getHost(), uri.getPort()));
final Future<Channel> acquire = simpleChannelPool.acquire();

acquire.addListener(new FutureListener<Channel>() {
public void operationComplete(Future<Channel> f) throws Exception {
if (f.isSuccess()) {
final Channel ch = f.getNow();
// Send the HTTP request.
ChannelFuture channelFuture = ch.writeAndFlush(request);
channelFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (channelFuture.isSuccess()) {
simpleChannelPool.release(ch);
} else {
}
}
});
} else {
System.out.println("ERROR : " + f.cause());
}
}
});

最佳答案

仅当您“获取”先前创建的 channel 时才会调用 channelAcquired 方法。在您的情况下,池中还没有 channel ,因此它将调用 channelCreated

关于java - Netty ChannelAcquired 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33140576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com