チャネルを再利用する接続プールを作成したいのですが、理解できませんでした
このテストの実行
public void test() {
ClientBootstrap client = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
client.setPipelineFactory(new ClientPipelineFactory());
// Connect to server, wait till connection is established, get channel to write to
Channel channel = client.connect(new InetSocketAddress("192.168.252.152", 8080)).awaitUninterruptibly().getChannel();
{
// Writing request to channel and wait till channel is closed from server
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "test");
String xml = "xml document here";
ChannelBuffer buffer = ChannelBuffers.copiedBuffer(msgXml, Charset.defaultCharset());
request.addHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
request.addHeader(HttpHeaders.Names.CONTENT_TYPE, "application/xml");
request.setContent(buffer);
channel.write(request).awaitUninterruptibly().getChannel().getCloseFuture().awaitUninterruptibly();
channel.write(request).awaitUninterruptibly().getChannel().getCloseFuture().awaitUninterruptibly();
}
client.releaseExternalResources();
}
2番目のchannel.write(request)...でClosedChannelExceptionが発生しました。
チャネルを再利用する方法はありますか?またはチャネルを開いたままにしますか?
前もって感謝します