content: package com.lgp.netty.netty_ch4;
  
  import io.netty.channel.*;
  import io.netty.handler.codec.marshalling.MarshallerProvider;
  import io.netty.handler.codec.marshalling.MarshallingDecoder;
  import io.netty.handler.codec.marshalling.MarshallingEncoder;
  import io.netty.handler.codec.marshalling.UnmarshallerProvider;
  
  import java.io.Serializable;
  
  /**
   * @AUTHOR lgp
   * @DATE 2018/12/29 16:19
   * @DESCRIPTION JBoss Marshalling 序列化
   **/
  public class MarshallingInitializer extends ChannelInitializer<Channel> {
  
      private final MarshallerProvider marshallerProvider;
      private final UnmarshallerProvider unmarshallerProvider;
  
      public MarshallingInitializer(UnmarshallerProvider unmarshallerProvider, MarshallerProvider marshallerProvider) {
          this.marshallerProvider = marshallerProvider;
          this.unmarshallerProvider = unmarshallerProvider;
      }
      @Override
      protected void initChannel(Channel channel) throws Exception {
          ChannelPipeline pipeline = channel.pipeline();
          pipeline.addLast(new MarshallingDecoder(unmarshallerProvider));
          pipeline.addLast(new MarshallingEncoder(marshallerProvider));
          pipeline.addLast(new ObjectHandler());
      }
  
      public static final class ObjectHandler extends SimpleChannelInboundHandler<Serializable> {
          @Override
          protected void channelRead0(ChannelHandlerContext channelHandlerContext, Serializable serializable) throws Exception {
          }
      }
  }
  