final AtomicReference<IoSession> c1 = new AtomicReference<IoSession>();
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch messageCount = new CountDownLatch(2);
IoAcceptor acceptor = new VmPipeAcceptor();
acceptor.setHandler(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);
}
}
});
acceptor.bind(address);
connector.setHandler(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());
IoConnector c2 = new VmPipeConnector();
c2.setHandler(new IoHandlerAdapter() {
@Override
public void sessionOpened(IoSession session) throws Exception {
session.write("re-use c1");
}