public Server build() { Preconditions.checkNotNull(serviceImpl); Preconditions.checkNotNull(serviceName); Preconditions.checkNotNull(zkConn); Preconditions.checkArgument(port > 0); return new ServerImpl(this.port, this.serviceImpl, this.serviceName, this.zkConn); } }
public void destroy() { rpcServer.shutdown(); }
@Override public void shutdown() { LOGGER.info("Shutting down server {}", serviceName); unRegister(); if (curatorFramework != null) { curatorFramework.close(); } started = false; bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); }
public void start() { Server build = ServerBuilder.builder().serviceImpl(serviceImpl) .serviceName(serviceName) .zkConn(zkConn).build(); build.start(); rpcServer = new ServerImpl(port, serviceImpl, serviceName); rpcServer.setZkConn(getZkConn()); rpcServer.start(); }
@Override public void start() { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline() .addLast(new LoggingHandler(LogLevel.INFO)) .addLast(new ProtocolDecoder(10 * 1024 * 1024)) .addLast(new ProtocolEncoder()) .addLast(new RpcServerHandler(serviceImpl)) ; } }); try { ChannelFuture sync = bootstrap.bind(port).sync(); registerService(); LOGGER.info("Server Started At {}", port); started = true; this.channel = sync.channel(); } catch (InterruptedException e) { e.printStackTrace(); } }
private void registerService() { String zkConn = getZkConn(); ip = InetUtil.getLocalIp(); String ipPortStr = ip + ":" + port;