final AtomicReference<IoSession> c1 = new AtomicReference<IoSession>();
final CountDownLatch latch = new CountDownLatch( 1 );
final CountDownLatch messageCount = new CountDownLatch( 2 );
IoAcceptor acceptor = new VmPipeAcceptor();
acceptor.bind( address, new IoHandlerAdapter() {
@Override
public void messageReceived( IoSession session, Object message ) throws Exception {
System.out.println( Thread.currentThread().getName() + ": " + message );
if ( "start".equals( message ) ) {
session.write( "open new" );
} else if ( "re-use c1".equals( message ) ) {
session.write( "tell me something on c1 now" );
} else if ( ( (String) message ).startsWith( "please don't deadlock" ) ) {
messageCount.countDown();
} else {
fail( "unexpected message received " + message );
}
}
} );
connector.getDefaultConfig().setThreadModel( ThreadModel.MANUAL );
ConnectFuture future = connector.connect( address, new IoHandlerAdapter() {
@Override
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() {
@Override
public void sessionOpened( IoSession session ) throws Exception {
session.write( "re-use c1" );
}