title: What's the best way to reconnect after connection closed in Netty
body: <p>Simple scenario:</p>
  
  <ol>
  <li>A lower level class A that extends SimpleChannelUpstreamHandler. This class is the workhorse to send the message and received the response. </li>
  <li><p>A top level class B that can be used by other part of the system to send and receive message (can simulate both Synchronous and Asynchronous). This class creates the ClientBootstrap, set the pipeline factory, invoke the bootstrap.connect() and eventually get a handle/reference of the class A through which to be used to send and receive message. Something like:</p>
  
  <pre><code>ChannelFuture future = bootstrap.connect();
  Channel channel = future.awaitUninterruptibly().getChannel();
  </code></pre>
  
  <p>A handler = channel.getPipeline().get(A.class);</p></li>
  </ol>
  
  <p>I know in class A, I can override 
      public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e);
  so that when the remote server is down, I can be notified. </p>
  
  <p>Since after channel is closed, the original class A reference (handler above) in class B is not valid anymore, so I need to replace it with a new reference. </p>
  
  <p>Ideally, I want class A to have a mechanism to notify class B within the above overrided channelClosed method so the bootstrap.connect can be invoked again within class B. One way to do this is to have a reference in class A that reference class B. To do that, I would need to pass class B reference to the PipelineFactory and then have the PipelineFactory pass the reference of B to A.</p>
  
  <p>Any other simpler way to achieve the same thing?</p>
  
  <p>thanks,</p>