1package muduo.rpc; 2 3import java.net.InetSocketAddress; 4import java.util.concurrent.Executors; 5 6import org.jboss.netty.bootstrap.ServerBootstrap; 7import org.jboss.netty.channel.Channel; 8import org.jboss.netty.channel.ChannelFactory; 9import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; 10 11public class RpcServer extends RpcPeer { 12 13 ServerBootstrap bootstrap; 14 15 public RpcServer() { 16 ChannelFactory channelFactory = new NioServerSocketChannelFactory( 17 Executors.newCachedThreadPool(), 18 Executors.newCachedThreadPool()); 19 bootstrap = new ServerBootstrap(channelFactory); 20 bootstrap.setPipelineFactory(new RpcChannelPiplineFactory(this)); 21 } 22 23 public void start(int port) { 24 bootstrap.bind(new InetSocketAddress(port)); 25 } 26 27 @Override 28 public void channelConnected(Channel channel) { 29 RpcChannel rpcChannel = new RpcChannel(channel); 30 setupNewChannel(rpcChannel); 31 } 32} 33