@Override public void setSessionId(long sessionId) { this.sessionId = sessionId; factory.addSession(sessionId, this); }
@Override public void configure(InetSocketAddress addr, int maxClientCnxns, boolean secure) throws IOException { configureSaslLogin(); localAddress = addr; this.maxClientCnxns = maxClientCnxns; this.secure = secure; }
@Override public void startup(ZooKeeperServer zks, boolean startServer) throws IOException, InterruptedException { start(); setZooKeeperServer(zks); if (startServer) { zks.startdata(); zks.startup(); } }
factory.unregisterConnection(this); factory.removeCnxnFromSessionMap(this); factory.removeCnxnFromIpMap( this, ((InetSocketAddress)channel.remoteAddress()).getAddress());
@Override public void close() { if (LOG.isDebugEnabled()) { LOG.debug("close called for sessionid:0x" + Long.toHexString(sessionId)); } // ZOOKEEPER-2743: // Always unregister connection upon close to prevent // connection bean leak under certain race conditions. factory.unregisterConnection(this); factory.removeCnxn(this); if (channel.isOpen()) { channel.close(); } }
}); closeAll(); ChannelGroupFuture allChannelsCloseFuture = allChannels.close(); if (workerGroup != null) {
@Override public void start() { LOG.info("binding to port {}", localAddress); parentChannel = bootstrap.bind(localAddress).syncUninterruptibly().channel(); // Port changes after bind() if the original port was 0, update // localAddress to get the real port. localAddress = (InetSocketAddress) parentChannel.localAddress(); LOG.info("bound to port " + getLocalPort()); }
NettyServerCnxnFactory() { x509Util = new ClientX509Util(); EventLoopGroup bossGroup = NettyUtils.newNioOrEpollEventLoopGroup(); EventLoopGroup workerGroup = NettyUtils.newNioOrEpollEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap() .group(bossGroup, workerGroup) .channel(NettyUtils.nioOrEpollServerSocketChannel()) // parent channel options .option(ChannelOption.SO_REUSEADDR, true) // child channels options .childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.SO_LINGER, -1) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (secure) { initSSL(pipeline); } pipeline.addLast("servercnxnfactory", channelHandler); } }); this.bootstrap = configureBootstrapAllocator(bootstrap); this.bootstrap.validate(); }
@Override public void tearDown() throws Exception { super.tearDown(); NettyServerCnxnFactory.clearTestAllocator(); TestByteBufAllocator.checkForLeaks(); }
/** * Starts the ZooKeeper Service in process. * * @throws Exception If an exception occurred. */ public void start() throws Exception { Preconditions.checkState(this.tmpDir.get() != null, "Not Initialized."); val s = new ZooKeeperServer(this.tmpDir.get(), this.tmpDir.get(), ZooKeeperServer.DEFAULT_TICK_TIME); if (!this.server.compareAndSet(null, s)) { s.shutdown(); throw new IllegalStateException("Already started."); } this.serverFactory.set(NettyServerCnxnFactory.createFactory()); val address = LOOPBACK_ADDRESS + ":" + this.zkPort; log.info("Starting Zookeeper server at " + address + " ..."); this.serverFactory.get().configure(new InetSocketAddress(LOOPBACK_ADDRESS, this.zkPort), 1000, secureZK); this.serverFactory.get().startup(s); if (!waitForServerUp(this.zkPort, this.secureZK, this.trustStore, this.keyStore, this.keyStorePassword, this.keyStorePassword)) { throw new IllegalStateException("ZooKeeper server failed to start"); } }
@Override public void shutdown() { LOG.info("shutdown called " + localAddress); if (login != null) { login.shutdown(); } // null if factory never started if (parentChannel != null) { parentChannel.close().awaitUninterruptibly(); closeAll(); allChannels.close().awaitUninterruptibly(); bootstrap.releaseExternalResources(); } if (zkServer != null) { zkServer.shutdown(); } synchronized(this) { killed = true; notifyAll(); } }
public void reconfigure(InetSocketAddress addr) { Channel oldChannel = parentChannel; try { LOG.info("binding to port {}", addr); parentChannel = bootstrap.bind(addr).syncUninterruptibly().channel(); // Port changes after bind() if the original port was 0, update // localAddress to get the real port. localAddress = (InetSocketAddress) parentChannel.localAddress(); LOG.info("bound to port " + getLocalPort()); } catch (Exception e) { LOG.error("Error while reconfiguring", e); } finally { oldChannel.close(); } }
@Override public void startup(ZooKeeperServer zks) throws IOException, InterruptedException { start(); setZooKeeperServer(zks); zks.startdata(); zks.startup(); }
@Override public void configure(InetSocketAddress addr, int maxClientCnxns) throws IOException { configureSaslLogin(); localAddress = addr; this.maxClientCnxns = maxClientCnxns; }
@Override public void setSessionId(long sessionId) { this.sessionId = sessionId; factory.addSession(sessionId, this); }