public void stop() throws IOException, InterruptedException { LOG.info("Stopping LlapOutputFormatService"); if (listeningChannelFuture != null) { listeningChannelFuture.channel().close().sync(); listeningChannelFuture = null; } else { LOG.warn("LlapOutputFormatService does not appear to have a listening port to close."); } eventLoopGroup.shutdownGracefully(1, WAIT_TIME, TimeUnit.SECONDS).sync(); }
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(); } } }
@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; }
@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(); } }
private void doStop() { if (future != null) { future.channel().close().syncUninterruptibly(); future = null; } if (group != null) { Future<?> groupFuture = group.shutdownGracefully(0, 0, TimeUnit.SECONDS); try { groupFuture.get(); } catch (Exception e) { throw new IllegalStateException(e); } group = null; } } }
EventLoopGroup cacheNioServerLoops() { EventLoopGroup eventLoopGroup = serverLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(workerCount, threadFactory(this, "nio")); if (!serverLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioServerLoops(); } return eventLoopGroup; }
public void run() throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ServerInitializer()); ChannelFuture ch = b.bind(port).sync(); ch.channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
/** * Listing 8.9 Graceful shutdown */ public void bootstrap() { EventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) //... .handler( new SimpleChannelInboundHandler<ByteBuf>() { @Override protected void channelRead0( ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { System.out.println("Received data"); } } ); bootstrap.connect(new InetSocketAddress("www.manning.com", 80)).syncUninterruptibly(); //,,, Future<?> future = group.shutdownGracefully(); // block until the group has shutdown future.syncUninterruptibly(); } }
/** * Notice: only {@link GlobalSwitch#SERVER_MANAGE_CONNECTION_SWITCH} switch on, will close all connections. * * @see AbstractRemotingServer#doStop() */ @Override protected boolean doStop() { if (null != this.channelFuture) { this.channelFuture.channel().close(); } if (this.switches().isOn(GlobalSwitch.SERVER_SYNC_STOP)) { this.bossGroup.shutdownGracefully().awaitUninterruptibly(); } else { this.bossGroup.shutdownGracefully(); } if (this.switches().isOn(GlobalSwitch.SERVER_MANAGE_CONNECTION_SWITCH) && null != this.connectionManager) { this.connectionManager.removeAll(); logger.warn("Close all connections from server side!"); } logger.warn("Rpc Server stopped!"); return true; }
try { try { serverChannel.close().sync(); } catch (InterruptedException e) { interrupted = true; Future<?> serverShutdownFuture = serverGroup.shutdownGracefully(); Future<?> clientShutdownFuture = clientGroup.shutdownGracefully(); try { serverShutdownFuture.sync();
public void start() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group) .channel(NioSocketChannel.class) .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( new EchoClientHandler()); } }); ChannelFuture f = b.connect().sync(); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } }
public void stop() throws IOException, InterruptedException { LOG.info("Stopping LlapOutputFormatService"); if (listeningChannelFuture != null) { listeningChannelFuture.channel().close().sync(); listeningChannelFuture = null; } else { LOG.warn("LlapOutputFormatService does not appear to have a listening port to close."); } eventLoopGroup.shutdownGracefully(1, WAIT_TIME, TimeUnit.SECONDS).sync(); }
public void close() { this.group.shutdownGracefully(); try { this.channel.closeFuture().sync(); } catch (Exception e) { e.printStackTrace(); } }
/** * 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 shutdown() { if (channelFuture != null) { channelFuture.channel().close().syncUninterruptibly(); } if (bossGroup != null) { bossGroup.shutdownGracefully(); } if (workGroup != null) { workGroup.shutdownGracefully(); } }
EventLoopGroup cacheNioServerLoops() { EventLoopGroup eventLoopGroup = serverLoops.get(); if (null == eventLoopGroup) { EventLoopGroup newEventLoopGroup = new NioEventLoopGroup(workerCount, threadFactory(this, "nio")); if (!serverLoops.compareAndSet(null, newEventLoopGroup)) { newEventLoopGroup.shutdownGracefully(); } eventLoopGroup = cacheNioServerLoops(); } return eventLoopGroup; }
@Override public void connectImpl(final String address, final int port) { LOGGER.info("Connecting to server {}:{}", address, port); ChannelFuture future = this.bootstrap.connect(new InetSocketAddress(address, port)); if (!future.awaitUninterruptibly().isSuccess()) { this.connectionFailed(); this.bootstrap.config().group().shutdownGracefully(); } else { this.channel = future.channel(); this.connectionComplete(); } }
@Override public void onShutdown() { try { channel.close().sync(); bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } catch (InterruptedException e) { logger.debug("Error shutting down WebSocket plugin", e); } }
public void start() throws Exception { final EchoServerHandler serverHandler = new EchoServerHandler(); EventLoopGroup group = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) .localAddress(new InetSocketAddress(port)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(serverHandler); } }); ChannelFuture f = b.bind().sync(); System.out.println(EchoServer.class.getName() + " started and listening for connections on " + f.channel().localAddress()); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } } }
channel = b.connect(uri.getHost(), port).sync().channel(); isDone = handler.handshakeFuture().sync().isSuccess(); } catch (Exception e) { LOGGER.debug("Handshake unsuccessful : " + e.getMessage(), e); group.shutdownGracefully(); return false;