Search in sources :

Example 56 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project wildfly-swarm by wildfly-swarm.

the class Server method stop.

public final synchronized void stop() throws ServerLifecycleException, IllegalStateException, InterruptedException {
    // Use an anonymous logger because the JUL LogManager will not log after process shutdown has been received
    final Logger log = Logger.getAnonymousLogger();
    log.addHandler(new Handler() {

        @Override
        public void publish(final LogRecord record) {
            System.out.println(PREFIX + record.getMessage());
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }

        private final String PREFIX = "[" + Server.class.getSimpleName() + "] ";
    });
    if (!this.isRunning()) {
        throw new IllegalStateException("Server is not running");
    }
    if (log.isLoggable(Level.INFO)) {
        log.info("Requesting shutdown...");
    }
    this.eventLoopGroups.forEach(EventLoopGroup::shutdownGracefully);
    this.eventLoopGroups.clear();
    shutdownService.shutdown();
    if (!shutdownService.awaitTermination(2, TimeUnit.MINUTES)) {
        log.warning("Unable to shutdown the server process cleanly.");
    }
    // Kill the shutdown service
    shutdownService.shutdownNow();
    shutdownService = null;
    // Not running
    running = false;
    if (log.isLoggable(Level.INFO)) {
        log.info("Server shutdown.");
    }
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) LogRecord(java.util.logging.LogRecord) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) Handler(java.util.logging.Handler) Logger(java.util.logging.Logger)

Example 57 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project reactor-netty by reactor.

the class TcpResourcesTest method before.

@Before
public void before() {
    loopDisposed = new AtomicBoolean();
    poolDisposed = new AtomicBoolean();
    loopResources = new LoopResources() {

        @Override
        public EventLoopGroup onServer(boolean useNative) {
            return null;
        }

        @Override
        public Mono<Void> disposeLater() {
            return Mono.<Void>empty().doOnSuccess(c -> loopDisposed.set(true));
        }

        @Override
        public boolean isDisposed() {
            return loopDisposed.get();
        }
    };
    poolResources = new PoolResources() {

        @Override
        public ChannelPool selectOrCreate(SocketAddress address, Supplier<? extends Bootstrap> bootstrap, Consumer<? super Channel> onChannelCreate, EventLoopGroup group) {
            return null;
        }

        public Mono<Void> disposeLater() {
            return Mono.<Void>empty().doOnSuccess(c -> poolDisposed.set(true));
        }

        @Override
        public boolean isDisposed() {
            return poolDisposed.get();
        }
    };
    tcpResources = new TcpResources(loopResources, poolResources);
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) SocketAddress(java.net.SocketAddress) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) PoolResources(reactor.ipc.netty.resources.PoolResources) InetSocketAddress(java.net.InetSocketAddress) Supplier(java.util.function.Supplier) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Channel(io.netty.channel.Channel) CountDownLatch(java.util.concurrent.CountDownLatch) Bootstrap(io.netty.bootstrap.Bootstrap) Flux(reactor.core.publisher.Flux) Duration(java.time.Duration) NettyContext(reactor.ipc.netty.NettyContext) ChannelPool(io.netty.channel.pool.ChannelPool) SocketUtils(reactor.ipc.netty.SocketUtils) LoopResources(reactor.ipc.netty.resources.LoopResources) Before(org.junit.Before) ChannelPool(io.netty.channel.pool.ChannelPool) Mono(reactor.core.publisher.Mono) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventLoopGroup(io.netty.channel.EventLoopGroup) PoolResources(reactor.ipc.netty.resources.PoolResources) LoopResources(reactor.ipc.netty.resources.LoopResources) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Before(org.junit.Before)

Example 58 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project reactor-netty by reactor.

the class DefaultLoopResources method disposeLater.

@Override
public Mono<Void> disposeLater() {
    return Mono.defer(() -> {
        EventLoopGroup cacheNativeClientGroup = cacheNativeClientLoops.get();
        EventLoopGroup cacheNativeSelectGroup = cacheNativeSelectLoops.get();
        EventLoopGroup cacheNativeServerGroup = cacheNativeServerLoops.get();
        if (running.compareAndSet(true, false)) {
            clientLoops.shutdownGracefully();
            serverSelectLoops.shutdownGracefully();
            serverLoops.shutdownGracefully();
            if (cacheNativeClientGroup != null) {
                cacheNativeClientGroup.shutdownGracefully();
            }
            if (cacheNativeSelectGroup != null) {
                cacheNativeSelectGroup.shutdownGracefully();
            }
            if (cacheNativeServerGroup != null) {
                cacheNativeServerGroup.shutdownGracefully();
            }
        }
        Mono<?> clMono = FutureMono.from((Future) clientLoops.terminationFuture());
        Mono<?> sslMono = FutureMono.from((Future) serverSelectLoops.terminationFuture());
        Mono<?> slMono = FutureMono.from((Future) serverLoops.terminationFuture());
        Mono<?> cnclMono = Mono.empty();
        if (cacheNativeClientGroup != null) {
            cnclMono = FutureMono.from((Future) cacheNativeClientGroup.terminationFuture());
        }
        Mono<?> cnslMono = Mono.empty();
        if (cacheNativeSelectGroup != null) {
            cnslMono = FutureMono.from((Future) cacheNativeSelectGroup.terminationFuture());
        }
        Mono<?> cnsrvlMono = Mono.empty();
        if (cacheNativeServerGroup != null) {
            cnsrvlMono = FutureMono.from((Future) cacheNativeServerGroup.terminationFuture());
        }
        return Mono.when(clMono, sslMono, slMono, cnclMono, cnslMono, cnsrvlMono);
    });
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Future(io.netty.util.concurrent.Future)

Example 59 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project reactor-netty by reactor.

the class DefaultLoopResources method cacheNativeSelectLoops.

EventLoopGroup cacheNativeSelectLoops() {
    if (cacheNativeSelectLoops == cacheNativeServerLoops) {
        return cacheNativeServerLoops();
    }
    EventLoopGroup eventLoopGroup = cacheNativeSelectLoops.get();
    if (null == eventLoopGroup) {
        DefaultLoop defaultLoop = DefaultLoopNativeDetector.getInstance();
        EventLoopGroup newEventLoopGroup = defaultLoop.newEventLoopGroup(selectCount, threadFactory(this, "select-" + defaultLoop.getName()));
        if (!cacheNativeSelectLoops.compareAndSet(null, newEventLoopGroup)) {
            newEventLoopGroup.shutdownGracefully();
        }
        eventLoopGroup = cacheNativeSelectLoops();
    }
    return eventLoopGroup;
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 60 with EventLoopGroup

use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project reactor-netty by reactor.

the class DefaultLoopResources method cacheNativeServerLoops.

EventLoopGroup cacheNativeServerLoops() {
    EventLoopGroup eventLoopGroup = cacheNativeServerLoops.get();
    if (null == eventLoopGroup) {
        DefaultLoop defaultLoop = DefaultLoopNativeDetector.getInstance();
        EventLoopGroup newEventLoopGroup = defaultLoop.newEventLoopGroup(workerCount, threadFactory(this, "server-" + defaultLoop.getName()));
        if (!cacheNativeServerLoops.compareAndSet(null, newEventLoopGroup)) {
            newEventLoopGroup.shutdownGracefully();
        }
        eventLoopGroup = cacheNativeServerLoops();
    }
    return eventLoopGroup;
}
Also used : EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

EventLoopGroup (io.netty.channel.EventLoopGroup)367 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)271 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)162 Bootstrap (io.netty.bootstrap.Bootstrap)137 Channel (io.netty.channel.Channel)131 ChannelFuture (io.netty.channel.ChannelFuture)129 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)109 SocketChannel (io.netty.channel.socket.SocketChannel)94 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)92 InetSocketAddress (java.net.InetSocketAddress)69 Test (org.junit.jupiter.api.Test)67 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)60 LoggingHandler (io.netty.handler.logging.LoggingHandler)55 ChannelPipeline (io.netty.channel.ChannelPipeline)51 SslContext (io.netty.handler.ssl.SslContext)51 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)50 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)49 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)46 LocalServerChannel (io.netty.channel.local.LocalServerChannel)42 LocalChannel (io.netty.channel.local.LocalChannel)40