title: Advantage of ChannelInitializer over Channel Handler in Netty
body: <p>What are the advantages of using ChannelInitializer over a chain of ChannelHandlers directly?</p>
  
  <p>For example with a server bootstrap I could do:</p>
  
  <pre><code>bootstrap.childHandler(channel_handler);
  </code></pre>
  
  <p>Add in the implementation of channel_handler i would implement the following</p>
  
  <pre><code>class simple_channel_handler implements ChannelHandler
  {
      public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
          // TODO Auto-generated method stub
          System.out.println("handler added");
          ctx.pipeline().addLast(new simple_channel_handler_2());
      }
  }
  </code></pre>
  
  <p>Where as in case of ChannelInitializer</p>
  
  <pre><code>        ch.pipeline().addLast(
                                 new channel_handler_1(), 
                                 new channel_handler_2()
                               );
  </code></pre>
  
  <p>And in each of the handler i could do </p>
  
  <pre><code>class channel_handler_1 extends ChannelInboundHandlerAdapter
  {
  
      @Override
      public void channelActive(ChannelHandlerContext ctx) throws Exception {
          // TODO Auto-generated method stub
          System.out.println("Channel just became active");
          ctx.fireChannelRead(ctx); // Fire directly to channel handler 2
      }
  }
  </code></pre>
  
  <p>So is the only advantage that channel handler one need not understand where it is firing the channel read to ? I don't see any other advantage of using a channel initializer</p>