}
// 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.
IoThreadPoolFilter ioThreadPoolFilter = new IoThreadPoolFilter();
ProtocolThreadPoolFilter protocolThreadPoolFilter = new ProtocolThreadPoolFilter();
// and start both.
ioThreadPoolFilter.start();
protocolThreadPoolFilter.start();
IoProtocolConnector connector = new IoProtocolConnector(
new SocketConnector() );
connector.getIoConnector().getFilterChain().addFirst( "threadPool",
ioThreadPoolFilter );
connector.getFilterChain().addFirst( "threadPool",
protocolThreadPoolFilter );
ProtocolProvider protocolProvider = new ClientProtocolProvider( values );
ProtocolSession session;
for( ;; )
{
try
{
session = connector.connect( new InetSocketAddress( HOSTNAME,
PORT ), CONNECT_TIMEOUT, protocolProvider );
break;
}
catch( IOException e )
{
System.err.println( "Failed to connect." );
e.printStackTrace();
Thread.sleep( 5000 );
}
}
// wait until the summation is done
while( session.isConnected() )
{
Thread.sleep( 100 );
}
ioThreadPoolFilter.stop();
protocolThreadPoolFilter.stop();
}