title: Netty Asynchronous Responses by Server Handler
body: <p>A server handler. For each received message, there will be multiple responses. Business Logic involves putting the requests in a queue, removing from the queue, processing the requests and responding.</p>
  
  <p>How do i process requests asynchronously, respond asynchronously while maintaining the integrity of the queue?</p>
  
  <p>The code below is behaves synchronously.</p>
  
  <pre><code>public class TestHandler extends SimpleChannelHandler {
  
      @Override
      public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
          // Send greeting for a new connection.
          e.getChannel().write(
                  "Welcome to " + InetAddress.getLocalHost().getHostName() + "!\r\n");
          e.getChannel().write("It is " + new Date() + " now.\r\n");
  
      }
  
      @Override
      public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {      
          String XMLFromClient = (String) e.getMessage() ;
  
          ReadXML2 rx = new ReadXML2();
          String response = null;
          response = rx.processInput(XMLFromClient);
          ChannelFuture future = e.getChannel().write(response);
      }
  
      @Override
      public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
          e.getCause().printStackTrace();
          Channel ch = e.getChannel();
          ch.close();
      } 
  }
  </code></pre>