1package muduo.rpc; 2 3import org.jboss.netty.channel.ChannelPipeline; 4import org.jboss.netty.channel.ChannelPipelineFactory; 5import org.jboss.netty.channel.Channels; 6import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; 7import org.jboss.netty.handler.codec.frame.LengthFieldPrepender; 8 9public class RpcChannelPiplineFactory implements ChannelPipelineFactory { 10 11 private RpcDecoder rpcDecoder = new RpcDecoder(); 12 private RpcEncoder rpcEncoder = new RpcEncoder(); 13 private LengthFieldPrepender frameEncoder = new LengthFieldPrepender(4); 14 private RpcPeer rpcPeer; 15 16 public RpcChannelPiplineFactory(RpcPeer peer) { 17 this.rpcPeer = peer; 18 } 19 20 @Override 21 public ChannelPipeline getPipeline() throws Exception { 22 ChannelPipeline p = Channels.pipeline(); 23 p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(16 * 1024 * 1024, 0, 4, 0, 4)); 24 p.addLast("rpcDecoder", rpcDecoder); 25 26 p.addLast("frameEncoder", frameEncoder); 27 p.addLast("rpcEncoder", rpcEncoder); 28 29 p.addLast("handler", new RpcMessageHandler(rpcPeer)); 30 return p; 31 } 32 33} 34