title: what's the sequence of channelhandler in netty?
body: <p>I have an application using netty to implement both server and client end. Server end sends the current time to client end. </p>
  
  <pre><code>public class TimeServerHandler extends ChannelInboundHandlerAdapter {
      @Override
      public void channelActive(ChannelHandlerContext ctx) {
          System.out.println("in timeserverhandler");
          ChannelFuture f = ctx.writeAndFlush(new UnixTime());
          f.addListener(ChannelFutureListener.CLOSE);
      }
  
      @Override
      public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
          cause.printStackTrace();
          ctx.close();
      }
  }
  </code></pre>
  
  <p>the encoder:  </p>
  
  <pre><code>  public class TimeEncoder extends ChannelOutboundHandlerAdapter {
      @Override
      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
          System.out.println("in timeencoder");
          UnixTime m = (UnixTime) msg;
          ByteBuf encoded = ctx.alloc().buffer(4);
          encoded.writeInt(m.value());
          ctx.write(encoded, promise); // (1)
      }
  
  
  }
  </code></pre>
  
  <blockquote>
    <p>public class TimeServer {
        private static final int PORT = 9000;</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      EventLoopGroup bossGroup = new NioEventLoopGroup(1);
      EventLoopGroup workerGroup = new NioEventLoopGroup();
      try {
          ServerBootstrap b = new ServerBootstrap();
          b.group(bossGroup, workerGroup)
                  .channel(NioServerSocketChannel.class)
                  .handler(new LoggingHandler(LogLevel.INFO))
                  .childHandler(new ChannelInitializer&lt;SocketChannel&gt;() {
                      @Override
                      public void initChannel(SocketChannel ch) {
                          ChannelPipeline p = ch.pipeline();
                          p.addLast(new TimeEncoder(), new TimeServerHandler());
                         //p.addLast(new TimeServerHandler(), new TimeEncoder());
  
                      }
                  });
          ChannelFuture f = b.bind(PORT).sync();
          f.channel().closeFuture().sync();
      } finally {
          workerGroup.shutdownGracefully();
          bossGroup.shutdownGracefully();
      }
  
  }
  </code></pre>
    
    <p>}  </p>
  </blockquote>
  
  <p>In TimeServer, if I change the <code>addList</code> sequnce to the commented line, the Encoder handler will never be called and client side can not print out the current time. Why is that, and what's the excute sequence of handlers in the pipeline?</p>