@Override public void join() throws InterruptedException { channel.closeFuture().sync(); }
public void run() { try { channelFuture.channel().closeFuture().sync(); LOG.info("FileServer exiting"); } catch (InterruptedException e) { LOG.error("File server start got interrupted", e); } // NOTE: bootstrap is shutdown in stop() } };
private void doCloseAsync() { if (allChannels.isEmpty()) { return; } final List<ChannelFuture> closeFutures = new ArrayList<>(allChannels.size()); for (Channel ch : allChannels.keySet()) { // NB: Do not call close() here, because it will trigger the closeFuture listener // which mutates allChannels. closeFutures.add(ch.closeFuture()); } closeFutures.forEach(f -> f.channel().close()); }
public void start() { try { ChannelFuture channelFuture = serverBootstrap.bind().sync(); channelFuture.channel().closeFuture().sync(); } catch (Exception e) { logger.error("fail to start the MQTTServer." + e); } finally { logger.info("shutdown the MQTTServer"); shutdown(); } }
@Override public void run() { try { InetSocketAddress inetSocketAddress; if (Strings.isNullOrEmpty(localBoundIP)) { inetSocketAddress = new InetSocketAddress(portToBind); } else { inetSocketAddress = new InetSocketAddress(localBoundIP, portToBind); } serverBootstrap .bind(inetSocketAddress) .addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { if (future.isSuccess()) { channelOpened.set(future.channel()); } else { channelOpened.setException(future.cause()); } } }) .channel().closeFuture().syncUninterruptibly(); } catch (Exception e) { throw new RuntimeException("Exception while binding MockServer to port " + portToBind, e); } } }, "MockServer thread for port: " + portToBind).start();
bootstrap.bind(configuration.bindAddress(), port).addListener(channelFuture -> { if (!channelFuture.isSuccess()) { LOGGER.info(() -> "Channel '" + name + "' startup failed with message '" Channel channel = ((ChannelFuture) channelFuture).channel(); LOGGER.info(() -> "Channel '" + name + "' started: " + channel); channels.put(name, channel); channel.closeFuture().addListener(future -> { LOGGER.info(() -> "Channel '" + name + "' closed: " + channel); channels.remove(name);
@SuppressWarnings("FutureReturnValueIgnored") public void close() throws InterruptedException { // Wait until the connection is closed. m_channel.closeFuture().sync().addListener(CLOSE_ON_FAILURE); if (workerGroup == null) { throw new IllegalStateException("Invoked close on an Acceptor that wasn't initialized"); } workerGroup.shutdownGracefully(); } }
public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Please give port as argument"); System.exit(1); } int port = Integer.parseInt(args[0]); final ChatServer endpoint = new ChatServer(); ChannelFuture future = endpoint.start( new InetSocketAddress(port)); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { endpoint.destroy(); } }); future.channel().closeFuture().syncUninterruptibly(); } }
@Override public void stop() { final Channel channel = channelReference.get(); if (channel != null) { channel.close(); channel.closeFuture().syncUninterruptibly(); } childChannels.close().syncUninterruptibly(); if (childEventLoopGroup != null) { childEventLoopGroup.shutdownGracefully(); } bootstrap = null; }
public final void run(final String host, final int port, final ChannelHandler pipelineFactory) { EventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .remoteAddress(host, port) .option(ChannelOption.TCP_NODELAY, true) .handler(pipelineFactory); try { Channel channel = bootstrap.connect().sync().channel(); ChannelFuture future = channel.closeFuture().sync(); future.addListener(ChannelFutureListener.CLOSE); } catch (InterruptedException e) { throw new MocoException(e); } finally { group.shutdownGracefully(); } } }
/** * Connects to the node and returns only upon connection close */ public void connect(String host, int port, String remoteId, boolean discoveryMode) { try { ChannelFuture f = connectAsync(host, port, remoteId, discoveryMode); f.sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); logger.debug("Connection is closed"); } catch (Exception e) { if (discoveryMode) { logger.trace("Exception:", e); } else { if (e instanceof IOException) { logger.info("PeerClient: Can't connect to " + host + ":" + port + " (" + e.getMessage() + ")"); logger.debug("PeerClient.connect(" + host + ":" + port + ") exception:", e); } else { logger.error("Exception:", e); } } } }
@Override public void join() throws InterruptedException { channel.closeFuture().sync(); }
/** * Start proxy server * */ public void start() throws InterruptedException { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.group(_acceptorGroup, _upstreamWorkerGroup); serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() { @Override public ServerChannel newChannel() { return new NioServerSocketChannel(); } }); serverBootstrap.childHandler(new ProxyInitializer(this)); //bind ChannelFuture future = serverBootstrap.bind(_host, _port); //wait for the future future.awaitUninterruptibly(); if (!future.isSuccess()) { future.channel().closeFuture().awaitUninterruptibly(); throw new ChannelException(String.format("Failed to bind to: %s:%d", _host, _port), future.cause()); } else { _allChannels.add(future.channel()); } }
@Override public void close() { // Wait until the server socket is closed. Exceptions.handleInterrupted(() -> { serverChannel.close(); serverChannel.closeFuture().sync(); }); // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
@Override public void operationComplete(ChannelFuture future) { ctx.pipeline().remove(DashboardWebSocketServerHandler.class); ctx.pipeline().remove(MockServerServerCodec.class); ctx.pipeline().remove(MockServerHandler.class); webSocketClientRegistry.registerClient(clientId, ctx); future.channel().closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) { webSocketClientRegistry.unregisterClient(clientId); } }); } });
public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Please give port as argument"); System.exit(1); } int port = Integer.parseInt(args[0]); SelfSignedCertificate cert = new SelfSignedCertificate(); SslContext context = SslContext.newServerContext( cert.certificate(), cert.privateKey()); final SecureChatServer endpoint = new SecureChatServer(context); ChannelFuture future = endpoint.start(new InetSocketAddress(port)); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { endpoint.destroy(); } }); future.channel().closeFuture().syncUninterruptibly(); } }
/** * Shutdown method for {@code GeodeRedisServer}. This closes the {@link Cache}, interrupts all * execution and forcefully closes all connections. */ public synchronized void shutdown() { if (!shutdown) { if (logger.infoEnabled()) logger.info("GeodeRedisServer shutting down"); ChannelFuture closeFuture = this.serverChannel.closeFuture(); Future<?> c = workerGroup.shutdownGracefully(); Future<?> c2 = bossGroup.shutdownGracefully(); this.serverChannel.close(); c.syncUninterruptibly(); c2.syncUninterruptibly(); this.regionCache.close(); if (mainThread != null) mainThread.interrupt(); for (ScheduledFuture<?> f : this.expirationFutures.values()) f.cancel(true); this.expirationFutures.clear(); this.expirationExecutor.shutdownNow(); closeFuture.syncUninterruptibly(); shutdown = true; } }
@Override public void run() { try { ServerBootstrap bootstrap = getServerBootstrap(); LOGGER.info("Binding to the server port !!"); // Bind and start to accept incoming connections. ChannelFuture f = bootstrap.bind(_port).sync(); _channel = f.channel(); LOGGER.info("Server bounded to port :" + _port + ", Waiting for closing"); f.channel().closeFuture().sync(); LOGGER.info("Server boss channel is closed. Gracefully shutting down the server netty threads and pipelines"); } catch (Exception e) { LOGGER.error("Got exception in the main server thread. Stopping !!", e); } finally { _shutdownComplete.set(true); } }
public void start(boolean sync) { serverGroup = new ServerGroup("Salamander", eventLoopConfig.acceptorCount(), eventLoopConfig.eventLoopCount(), eventLoopGroupMetrics); serverGroup.initializeTransport(); try { List<ChannelFuture> allBindFutures = new ArrayList<>(); // Setup each of the channel initializers on requested ports. for (Map.Entry<Integer, ChannelInitializer> entry : portsToChannelInitializers.entrySet()) { allBindFutures.add(setupServerBootstrap(entry.getKey(), entry.getValue())); } // Once all server bootstraps are successfully initialized, then bind to each port. for (ChannelFuture f: allBindFutures) { // Wait until the server socket is closed. ChannelFuture cf = f.channel().closeFuture(); if (sync) { cf.sync(); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } }
@Override public void join() throws InterruptedException { ch.closeFuture().sync(); }