RpcServer.java revision 420c9859
1420c9859SShuo Chenpackage muduo.rpc;
2420c9859SShuo Chen
3420c9859SShuo Chenimport java.net.InetSocketAddress;
4420c9859SShuo Chenimport java.util.concurrent.Executors;
5420c9859SShuo Chen
6420c9859SShuo Chenimport org.jboss.netty.bootstrap.ServerBootstrap;
7420c9859SShuo Chenimport org.jboss.netty.channel.Channel;
8420c9859SShuo Chenimport org.jboss.netty.channel.ChannelFactory;
9420c9859SShuo Chenimport org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
10420c9859SShuo Chen
11420c9859SShuo Chenpublic class RpcServer extends RpcPeer {
12420c9859SShuo Chen
13420c9859SShuo Chen    ServerBootstrap bootstrap;
14420c9859SShuo Chen
15420c9859SShuo Chen    public RpcServer() {
16420c9859SShuo Chen        ChannelFactory channelFactory = new NioServerSocketChannelFactory(
17420c9859SShuo Chen                Executors.newCachedThreadPool(),
18420c9859SShuo Chen                Executors.newCachedThreadPool());
19420c9859SShuo Chen        bootstrap = new ServerBootstrap(channelFactory);
20420c9859SShuo Chen        bootstrap.setPipelineFactory(new RpcChannelPiplineFactory(this));
21420c9859SShuo Chen    }
22420c9859SShuo Chen
23420c9859SShuo Chen    public void start(int port) {
24420c9859SShuo Chen        bootstrap.bind(new InetSocketAddress(port));
25420c9859SShuo Chen    }
26420c9859SShuo Chen
27420c9859SShuo Chen    @Override
28420c9859SShuo Chen    public void channelConnected(Channel channel) {
29420c9859SShuo Chen        RpcChannel rpcChannel = new RpcChannel(channel);
30420c9859SShuo Chen        setupNewChannel(rpcChannel);
31420c9859SShuo Chen    }
32420c9859SShuo Chen}
33