Elegant shutdown for DiscardClient

This commit is contained in:
Trustin Lee 2008-11-28 05:36:12 +00:00
parent e0e282770f
commit 70b87f84df

View File

@ -27,9 +27,8 @@ import java.util.concurrent.Executors;
import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.jboss.netty.handler.execution.ExecutionHandler;
import org.jboss.netty.handler.execution.MemoryAwareThreadPoolExecutor;
/**
* Keeps sending random data to the specified address.
@ -70,12 +69,17 @@ public class DiscardClient {
ClientBootstrap bootstrap = new ClientBootstrap(factory);
DiscardClientHandler handler = new DiscardClientHandler(firstMessageSize);
bootstrap.getPipeline().addLast("executor", new ExecutionHandler(new MemoryAwareThreadPoolExecutor(16, 0, 0)));
bootstrap.getPipeline().addLast("handler", handler);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
// Start the connection attempt.
bootstrap.connect(new InetSocketAddress(host, port));
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
// Wait until the connection is closed or the connection attempt fails.
future.getChannel().getCloseFuture().awaitUninterruptibly();
// Shut down thread pools to exit.
factory.getExternalResource().release();
}
}