}
} );
connector.getDefaultConfig().setThreadModel( ThreadModel.MANUAL );
ConnectFuture future = connector.connect( address, new IoHandlerAdapter() {
public void messageReceived( IoSession session, Object message ) throws Exception {
System.out.println( Thread.currentThread().getName() + ": " + message );
if ( "open new".equals( message ) ) {
System.out.println( "opening c2 from " + Thread.currentThread().getName() );
ConnectFuture c2Future = connector.connect( address, new IoHandlerAdapter() {
public void sessionOpened( IoSession session ) throws Exception {
session.write( "re-use c1" );
}
public void messageReceived( IoSession session, Object message ) throws Exception {
System.out.println( Thread.currentThread().getName() + ": " + message );
if ( "tell me something on c1 now".equals( message ) ) {
latch.countDown();
((IoSession) c1.get()).write( "please don't deadlock via c1" );
} else {
fail( "unexpected message received " + message );
}
}
} );
c2Future.join();
latch.await();
c2Future.getSession().write( "please don't deadlock via c2" );
} else {
fail( "unexpeced message received " + message );
}
}
} );