List of usage examples for io.netty.channel.group ChannelGroupFuture addListener
@Override
ChannelGroupFuture addListener(GenericFutureListener<? extends Future<? super Void>> listener);
From source file:com.barchart.netty.server.base.AbstractServer.java
License:BSD License
@Override public Future<T> shutdown() { if (serverChannels.size() == 0) { throw new IllegalStateException("Server is not running."); }/*ww w. j ava 2 s. c om*/ final ChannelGroupFuture future = serverChannels.close(); future.addListener(new ServerGroupCloseListener()); return shutdownFuture; }
From source file:com.barchart.netty.server.base.AbstractServer.java
License:BSD License
@Override public Future<T> kill() { if (serverChannels.size() == 0) { throw new IllegalStateException("Server is not running."); }/*from www .ja va2 s .co m*/ serverChannels.addAll(clientChannels); final ChannelGroupFuture future = serverChannels.close(); future.addListener(new AllGroupCloseListener()); return shutdownFuture; }
From source file:io.advantageous.conekt.http.impl.HttpServerImpl.java
License:Open Source License
private void actualClose(final ContextImpl closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); }/* w w w . j av a 2 s . c o m*/ ContextImpl currCon = vertx.getContext(); for (ServerConnection conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
From source file:io.advantageous.conekt.net.impl.NetServerImpl.java
License:Open Source License
private void actualClose(ContextImpl closeContext, Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedNetServers().remove(id); }/*from ww w . ja va2 s .com*/ ContextImpl currCon = vertx.getContext(); for (NetSocketImpl sock : socketMap.values()) { sock.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cg -> { if (metrics != null) { metrics.close(); } executeCloseDone(closeContext, done, fut.cause()); }); }
From source file:io.jsync.http.impl.DefaultHttpServer.java
License:Open Source License
private void actualClose(final DefaultContext closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { async.sharedHttpServers().remove(id); }/*from w ww . j a v a 2s . c o m*/ for (ServerConnection conn : connectionMap.values()) { conn.close(); } // We need to reset it since sock.internalClose() above can call into the close handlers of sockets on the same thread // which can cause context id for the thread to change! async.setContext(closeContext); final CountDownLatch latch = new CountDownLatch(1); ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception { latch.countDown(); } }); // Always sync try { latch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { } executeCloseDone(closeContext, done, fut.cause()); }
From source file:io.jsync.net.impl.DefaultNetServer.java
License:Open Source License
private void actualClose(final DefaultContext closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { async.sharedNetServers().remove(id); }//from w w w .j av a2 s .c om for (DefaultNetSocket sock : socketMap.values()) { sock.close(); } // We need to reset it since sock.internalClose() above can call into the close handlers of sockets on the same thread // which can cause context id for the thread to change! async.setContext(closeContext); ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(new ChannelGroupFutureListener() { public void operationComplete(ChannelGroupFuture fut) throws Exception { executeCloseDone(closeContext, done, fut.cause()); } }); }
From source file:io.vertx.core.http.impl.HttpServerImpl.java
License:Open Source License
private void actualClose(final ContextImpl closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); }/*from ww w. java2 s . c om*/ ContextImpl currCon = vertx.getContext(); for (ServerConnection conn : connectionMap.values()) { conn.close(); } for (Http2ServerConnection conn : connectionMap2.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
From source file:io.vertx.core.net.impl.NetServerBase.java
License:Open Source License
private void actualClose(ContextImpl closeContext, Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedNetServers().remove(id); }// www .ja v a2s.c o m ContextImpl currCon = vertx.getContext(); for (C sock : socketMap.values()) { sock.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cg -> { if (metrics != null) { metrics.close(); } executeCloseDone(closeContext, done, fut.cause()); }); }
From source file:org.apache.zookeeper.server.NettyServerCnxnFactory.java
License:Apache License
@Override public void shutdown() { synchronized (this) { if (killed) { LOG.info("already shutdown {}", localAddress); return; }//w w w . jav a2 s . c om } LOG.info("shutdown called {}", localAddress); x509Util.close(); if (login != null) { login.shutdown(); } final EventLoopGroup bossGroup = bootstrap.config().group(); final EventLoopGroup workerGroup = bootstrap.config().childGroup(); // null if factory never started if (parentChannel != null) { ChannelFuture parentCloseFuture = parentChannel.close(); if (bossGroup != null) { parentCloseFuture.addListener(future -> { bossGroup.shutdownGracefully(); }); } closeAll(); ChannelGroupFuture allChannelsCloseFuture = allChannels.close(); if (workerGroup != null) { allChannelsCloseFuture.addListener(future -> { workerGroup.shutdownGracefully(); }); } } else { if (bossGroup != null) { bossGroup.shutdownGracefully(); } if (workerGroup != null) { workerGroup.shutdownGracefully(); } } if (zkServer != null) { zkServer.shutdown(); } synchronized (this) { killed = true; notifyAll(); } }
From source file:org.robotninjas.protobuf.netty.server.RpcServer.java
License:Open Source License
@Override protected void doStop() { try {//from w w w . j a v a 2 s .co m ChannelGroupFuture f = allChannels.close(); f.addListener(new ChannelGroupFutureListener() { @Override public void operationComplete(ChannelGroupFuture future) throws Exception { if (future.isSuccess()) { notifyStopped(); } else { notifyFailed(future.cause()); } } }); } catch (Throwable t) { notifyFailed(t); Throwables.propagate(t); } }