Search in sources :

Example 1 with ChannelGroupFuture

use of io.netty.channel.group.ChannelGroupFuture in project vert.x by eclipse.

the class HttpServerImpl method actualClose.

private void actualClose(final ContextImpl closeContext, final Handler<AsyncResult<Void>> done) {
    if (id != null) {
        vertx.sharedHttpServers().remove(id);
    }
    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()));
}
Also used : ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture) ContextImpl(io.vertx.core.impl.ContextImpl)

Example 2 with ChannelGroupFuture

use of io.netty.channel.group.ChannelGroupFuture in project vert.x by eclipse.

the class NetServerBase method actualClose.

private void actualClose(ContextImpl closeContext, Handler<AsyncResult<Void>> done) {
    if (id != null) {
        vertx.sharedNetServers().remove(id);
    }
    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());
    });
}
Also used : ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture) ContextImpl(io.vertx.core.impl.ContextImpl)

Example 3 with ChannelGroupFuture

use of io.netty.channel.group.ChannelGroupFuture in project rest.li by linkedin.

the class HttpNettyClient method shutdown.

@Override
public void shutdown(final Callback<None> callback) {
    LOG.info("Shutdown requested");
    if (_state.compareAndSet(State.RUNNING, State.SHUTTING_DOWN)) {
        LOG.info("Shutting down");
        final long deadline = System.currentTimeMillis() + _shutdownTimeout;
        TimeoutCallback<None> closeChannels = new TimeoutCallback<None>(_scheduler, _shutdownTimeout, TimeUnit.MILLISECONDS, new Callback<None>() {

            private void finishShutdown() {
                _state.set(State.REQUESTS_STOPPING);
                // Timeout any waiters which haven't received a Channel yet
                for (Callback<Channel> callback : _channelPoolManager.cancelWaiters()) {
                    callback.onError(new TimeoutException("Operation did not complete before shutdown"));
                }
                // Timeout any requests still pending response
                for (Channel c : _allChannels) {
                    TransportCallback<RestResponse> callback = c.attr(RAPResponseHandler.CALLBACK_ATTR_KEY).getAndRemove();
                    if (callback != null) {
                        errorResponse(callback, new TimeoutException("Operation did not complete before shutdown"));
                    }
                }
                // Close all active and idle Channels
                final TimeoutRunnable afterClose = new TimeoutRunnable(_scheduler, deadline - System.currentTimeMillis(), TimeUnit.MILLISECONDS, new Runnable() {

                    @Override
                    public void run() {
                        _state.set(State.SHUTDOWN);
                        LOG.info("Shutdown complete");
                        callback.onSuccess(None.none());
                    }
                }, "Timed out waiting for channels to close, continuing shutdown");
                _allChannels.close().addListener(new ChannelGroupFutureListener() {

                    @Override
                    public void operationComplete(ChannelGroupFuture channelGroupFuture) throws Exception {
                        if (!channelGroupFuture.isSuccess()) {
                            LOG.warn("Failed to close some connections, ignoring");
                        }
                        afterClose.run();
                    }
                });
            }

            @Override
            public void onSuccess(None none) {
                LOG.info("All connection pools shut down, closing all channels");
                finishShutdown();
            }

            @Override
            public void onError(Throwable e) {
                LOG.warn("Error shutting down HTTP connection pools, ignoring and continuing shutdown", e);
                finishShutdown();
            }
        }, "Connection pool shutdown timeout exceeded (" + _shutdownTimeout + "ms)");
        _channelPoolManager.shutdown(closeChannels);
        _jmxManager.onProviderShutdown(_channelPoolManager);
    } else {
        callback.onError(new IllegalStateException("Shutdown has already been requested."));
    }
}
Also used : TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) TimeoutRunnable(com.linkedin.r2.util.TimeoutRunnable) ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) ChannelGroupFutureListener(io.netty.channel.group.ChannelGroupFutureListener) TransportCallback(com.linkedin.r2.transport.common.bridge.common.TransportCallback) Callback(com.linkedin.common.callback.Callback) TimeoutRunnable(com.linkedin.r2.util.TimeoutRunnable) None(com.linkedin.common.util.None) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with ChannelGroupFuture

use of io.netty.channel.group.ChannelGroupFuture in project camel by apache.

the class NettyProducer method doStop.

@Override
protected void doStop() throws Exception {
    LOG.debug("Stopping producer at address: {}", configuration.getAddress());
    // close all channels
    LOG.trace("Closing {} channels", allChannels.size());
    ChannelGroupFuture future = allChannels.close();
    future.awaitUninterruptibly();
    // and then shutdown the thread pools
    if (workerGroup != null) {
        workerGroup.shutdownGracefully();
        workerGroup = null;
    }
    if (pool != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Stopping producer with channel pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle());
        }
        pool.close();
        pool = null;
    }
    super.doStop();
}
Also used : ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture)

Example 5 with ChannelGroupFuture

use of io.netty.channel.group.ChannelGroupFuture in project spring-framework by spring-projects.

the class ReactorNettyTcpClient method shutdown.

@Override
public ListenableFuture<Void> shutdown() {
    if (this.stopping) {
        SettableListenableFuture<Void> future = new SettableListenableFuture<>();
        future.set(null);
        return future;
    }
    this.stopping = true;
    ChannelGroupFuture close = this.channelGroup.close();
    Mono<Void> completion = FutureMono.from(close).doAfterTerminate((x, e) -> {
        // TODO: https://github.com/reactor/reactor-netty/issues/24
        shutdownGlobalResources();
        this.loopResources.dispose();
        this.poolResources.dispose();
        // TODO: https://github.com/reactor/reactor-netty/issues/25
        try {
            Thread.sleep(2000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        // Scheduler after loop resources...
        this.scheduler.dispose();
    });
    return new MonoToListenableFutureAdapter<>(completion);
}
Also used : SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) ChannelGroupFuture(io.netty.channel.group.ChannelGroupFuture)

Aggregations

ChannelGroupFuture (io.netty.channel.group.ChannelGroupFuture)5 ContextImpl (io.vertx.core.impl.ContextImpl)2 Callback (com.linkedin.common.callback.Callback)1 None (com.linkedin.common.util.None)1 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)1 TimeoutRunnable (com.linkedin.r2.util.TimeoutRunnable)1 Channel (io.netty.channel.Channel)1 ChannelGroupFutureListener (io.netty.channel.group.ChannelGroupFutureListener)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 TimeoutException (java.util.concurrent.TimeoutException)1 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)1