// Create I/O and Protocol thread pool filter.
// I/O thread pool performs encoding and decoding of messages.
// Protocol thread pool performs actual protocol flow.
ThreadPoolFilter ioThreadPoolFilter = new ThreadPoolFilter();
ThreadPoolFilter protocolThreadPoolFilter = new ThreadPoolFilter();
IoConnector connector = new SocketConnector();
connector.getDefaultConfig().getFilterChain().addFirst(
"ioThreadPool", ioThreadPoolFilter );
connector.getDefaultConfig().getFilterChain().addLast(
"protocolThreadPool", protocolThreadPoolFilter );
// Set connect timeout.
( ( IoConnectorConfig ) connector.getDefaultConfig() ).setConnectTimeout( CONNECT_TIMEOUT );
IoSession session;
for( ;; )
{
try
{
ConnectFuture future = connector.connect(
new InetSocketAddress( HOSTNAME, PORT ),
new ClientSessionHandler( USE_CUSTOM_CODEC, values ) );
future.join();
session = future.getSession();