Search in sources :

Example 1 with NetServerBase

use of io.vertx.core.net.impl.NetServerBase in project vert.x by eclipse.

the class VertxImpl method close.

@Override
public synchronized void close(Handler<AsyncResult<Void>> completionHandler) {
    if (closed || eventBus == null) {
        // Just call the handler directly since pools shutdown
        if (completionHandler != null) {
            completionHandler.handle(Future.succeededFuture());
        }
        return;
    }
    closed = true;
    closeHooks.run(ar -> {
        deploymentManager.undeployAll(ar1 -> {
            if (haManager() != null) {
                haManager().stop();
            }
            addressResolver.close(ar2 -> {
                eventBus.close(ar3 -> {
                    closeClusterManager(ar4 -> {
                        Set<HttpServer> httpServers = new HashSet<>(sharedHttpServers.values());
                        Set<NetServerBase> netServers = new HashSet<>(sharedNetServers.values());
                        sharedHttpServers.clear();
                        sharedNetServers.clear();
                        int serverCount = httpServers.size() + netServers.size();
                        AtomicInteger serverCloseCount = new AtomicInteger();
                        Handler<AsyncResult<Void>> serverCloseHandler = res -> {
                            if (res.failed()) {
                                log.error("Failure in shutting down server", res.cause());
                            }
                            if (serverCloseCount.incrementAndGet() == serverCount) {
                                deleteCacheDirAndShutdown(completionHandler);
                            }
                        };
                        for (HttpServer server : httpServers) {
                            server.close(serverCloseHandler);
                        }
                        for (NetServerBase server : netServers) {
                            server.close(serverCloseHandler);
                        }
                        if (serverCount == 0) {
                            deleteCacheDirAndShutdown(completionHandler);
                        }
                    });
                });
            });
        });
    });
}
Also used : HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) NetServerImpl(io.vertx.core.net.impl.NetServerImpl) HttpClientImpl(io.vertx.core.http.impl.HttpClientImpl) HttpServer(io.vertx.core.http.HttpServer) NetClientImpl(io.vertx.core.net.impl.NetClientImpl) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) Context(io.vertx.core.Context) InetAddress(java.net.InetAddress) EventBus(io.vertx.core.eventbus.EventBus) WindowsFileSystem(io.vertx.core.file.impl.WindowsFileSystem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) DatagramSocketOptions(io.vertx.core.datagram.DatagramSocketOptions) Logger(io.vertx.core.logging.Logger) ThreadFactory(java.util.concurrent.ThreadFactory) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) VertxMetricsFactory(io.vertx.core.spi.VertxMetricsFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) MetricsProvider(io.vertx.core.spi.metrics.MetricsProvider) EventLoop(io.netty.channel.EventLoop) ResourceLeakDetector(io.netty.util.ResourceLeakDetector) Future(io.vertx.core.Future) ServerID(io.vertx.core.net.impl.ServerID) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Executors(java.util.concurrent.Executors) NetClientOptions(io.vertx.core.net.NetClientOptions) DnsClient(io.vertx.core.dns.DnsClient) Objects(java.util.Objects) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) NetServerOptions(io.vertx.core.net.NetServerOptions) PoolMetrics(io.vertx.core.spi.metrics.PoolMetrics) FileSystem(io.vertx.core.file.FileSystem) HttpClient(io.vertx.core.http.HttpClient) DatagramSocketImpl(io.vertx.core.datagram.impl.DatagramSocketImpl) VerticleFactory(io.vertx.core.spi.VerticleFactory) DatagramSocket(io.vertx.core.datagram.DatagramSocket) DnsClientImpl(io.vertx.core.dns.impl.DnsClientImpl) NetServerBase(io.vertx.core.net.impl.NetServerBase) HashMap(java.util.HashMap) LoggerFactory(io.vertx.core.logging.LoggerFactory) SharedData(io.vertx.core.shareddata.SharedData) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) TimeoutStream(io.vertx.core.TimeoutStream) HashSet(java.util.HashSet) ServiceHelper(io.vertx.core.ServiceHelper) SharedDataImpl(io.vertx.core.shareddata.impl.SharedDataImpl) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) NetClient(io.vertx.core.net.NetClient) Metrics(io.vertx.core.spi.metrics.Metrics) ExecutorService(java.util.concurrent.ExecutorService) EventBusImpl(io.vertx.core.eventbus.impl.EventBusImpl) Closeable(io.vertx.core.Closeable) EventLoopGroup(io.netty.channel.EventLoopGroup) Vertx(io.vertx.core.Vertx) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) Verticle(io.vertx.core.Verticle) File(java.io.File) FileSystemImpl(io.vertx.core.file.impl.FileSystemImpl) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DeploymentOptions(io.vertx.core.DeploymentOptions) NetServer(io.vertx.core.net.NetServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) ClusteredEventBus(io.vertx.core.eventbus.impl.clustered.ClusteredEventBus) Handler(io.vertx.core.Handler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NetServerBase(io.vertx.core.net.impl.NetServerBase) HttpServer(io.vertx.core.http.HttpServer) AsyncResult(io.vertx.core.AsyncResult) HashSet(java.util.HashSet)

Aggregations

EventLoop (io.netty.channel.EventLoop)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 AddressResolverGroup (io.netty.resolver.AddressResolverGroup)1 ResourceLeakDetector (io.netty.util.ResourceLeakDetector)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 AsyncResult (io.vertx.core.AsyncResult)1 Closeable (io.vertx.core.Closeable)1 Context (io.vertx.core.Context)1 DeploymentOptions (io.vertx.core.DeploymentOptions)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 ServiceHelper (io.vertx.core.ServiceHelper)1 TimeoutStream (io.vertx.core.TimeoutStream)1 Verticle (io.vertx.core.Verticle)1 Vertx (io.vertx.core.Vertx)1 VertxOptions (io.vertx.core.VertxOptions)1 DatagramSocket (io.vertx.core.datagram.DatagramSocket)1 DatagramSocketOptions (io.vertx.core.datagram.DatagramSocketOptions)1 DatagramSocketImpl (io.vertx.core.datagram.impl.DatagramSocketImpl)1