Netty channelAcquired 没有被调用
Netty channelAcquired is not getting called
我正在为 http 客户端使用 netty 通道池,在 ChannelPoolHandler
实现中 channelAcquired
在调用 channelPool.acquire()
时未被调用。我正在使用 netty 4.0.32.Final
。这是我创建香奈儿池的方法。我只是遵循 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());
}
}
});
仅当您 "acquire" 之前创建的频道时才会调用 channelAcquired
方法。在您的情况下,池中还没有频道,因此它将调用 channelCreated
.
我正在为 http 客户端使用 netty 通道池,在 ChannelPoolHandler
实现中 channelAcquired
在调用 channelPool.acquire()
时未被调用。我正在使用 netty 4.0.32.Final
。这是我创建香奈儿池的方法。我只是遵循 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());
}
}
});
仅当您 "acquire" 之前创建的频道时才会调用 channelAcquired
方法。在您的情况下,池中还没有频道,因此它将调用 channelCreated
.