1420c9859SShuo Chenpackage muduo.rpc;
2420c9859SShuo Chen
3420c9859SShuo Chenimport org.jboss.netty.channel.ChannelPipeline;
4420c9859SShuo Chenimport org.jboss.netty.channel.ChannelPipelineFactory;
5420c9859SShuo Chenimport org.jboss.netty.channel.Channels;
6420c9859SShuo Chenimport org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
7420c9859SShuo Chenimport org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
8420c9859SShuo Chen
9420c9859SShuo Chenpublic class RpcChannelPiplineFactory implements ChannelPipelineFactory {
10420c9859SShuo Chen
11420c9859SShuo Chen    private RpcDecoder rpcDecoder = new RpcDecoder();
12420c9859SShuo Chen    private RpcEncoder rpcEncoder = new RpcEncoder();
13420c9859SShuo Chen    private LengthFieldPrepender frameEncoder = new LengthFieldPrepender(4);
14420c9859SShuo Chen    private RpcPeer rpcPeer;
15420c9859SShuo Chen
16420c9859SShuo Chen    public RpcChannelPiplineFactory(RpcPeer peer) {
17420c9859SShuo Chen        this.rpcPeer = peer;
18420c9859SShuo Chen    }
19420c9859SShuo Chen
20420c9859SShuo Chen    @Override
21420c9859SShuo Chen    public ChannelPipeline getPipeline() throws Exception {
22420c9859SShuo Chen        ChannelPipeline p = Channels.pipeline();
23420c9859SShuo Chen        p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(16 * 1024 * 1024, 0, 4, 0, 4));
24420c9859SShuo Chen        p.addLast("rpcDecoder", rpcDecoder);
25420c9859SShuo Chen
26420c9859SShuo Chen        p.addLast("frameEncoder", frameEncoder);
27420c9859SShuo Chen        p.addLast("rpcEncoder", rpcEncoder);
28420c9859SShuo Chen
29420c9859SShuo Chen        p.addLast("handler", new RpcMessageHandler(rpcPeer));
30420c9859SShuo Chen        return p;
31420c9859SShuo Chen    }
32420c9859SShuo Chen
33420c9859SShuo Chen}
34