Search in sources :

Example 1 with SelectStrategyFactory

use of io.netty.channel.SelectStrategyFactory in project netty by netty.

the class NioEventLoopGroup method newChild.

@Override
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
    SelectorProvider selectorProvider = (SelectorProvider) args[0];
    SelectStrategyFactory selectStrategyFactory = (SelectStrategyFactory) args[1];
    RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[2];
    EventLoopTaskQueueFactory taskQueueFactory = null;
    EventLoopTaskQueueFactory tailTaskQueueFactory = null;
    int argsLength = args.length;
    if (argsLength > 3) {
        taskQueueFactory = (EventLoopTaskQueueFactory) args[3];
    }
    if (argsLength > 4) {
        tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[4];
    }
    return new NioEventLoop(this, executor, selectorProvider, selectStrategyFactory.newSelectStrategy(), rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
}
Also used : EventLoopTaskQueueFactory(io.netty.channel.EventLoopTaskQueueFactory) DefaultSelectStrategyFactory(io.netty.channel.DefaultSelectStrategyFactory) SelectStrategyFactory(io.netty.channel.SelectStrategyFactory) SelectorProvider(java.nio.channels.spi.SelectorProvider) RejectedExecutionHandler(io.netty.util.concurrent.RejectedExecutionHandler)

Example 2 with SelectStrategyFactory

use of io.netty.channel.SelectStrategyFactory in project netty by netty.

the class KQueueEventLoopGroup method newChild.

@Override
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
    Integer maxEvents = (Integer) args[0];
    SelectStrategyFactory selectStrategyFactory = (SelectStrategyFactory) args[1];
    RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[2];
    EventLoopTaskQueueFactory taskQueueFactory = null;
    EventLoopTaskQueueFactory tailTaskQueueFactory = null;
    int argsLength = args.length;
    if (argsLength > 3) {
        taskQueueFactory = (EventLoopTaskQueueFactory) args[3];
    }
    if (argsLength > 4) {
        tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[4];
    }
    return new KQueueEventLoop(this, executor, maxEvents, selectStrategyFactory.newSelectStrategy(), rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
}
Also used : EventLoopTaskQueueFactory(io.netty.channel.EventLoopTaskQueueFactory) DefaultSelectStrategyFactory(io.netty.channel.DefaultSelectStrategyFactory) SelectStrategyFactory(io.netty.channel.SelectStrategyFactory) RejectedExecutionHandler(io.netty.util.concurrent.RejectedExecutionHandler)

Example 3 with SelectStrategyFactory

use of io.netty.channel.SelectStrategyFactory in project netty by netty.

the class NioEventLoopTest method testRebuildSelectorOnIOException.

@Test
public void testRebuildSelectorOnIOException() {
    SelectStrategyFactory selectStrategyFactory = new SelectStrategyFactory() {

        @Override
        public SelectStrategy newSelectStrategy() {
            return new SelectStrategy() {

                private boolean thrown;

                @Override
                public int calculateStrategy(IntSupplier selectSupplier, boolean hasTasks) throws Exception {
                    if (!thrown) {
                        thrown = true;
                        throw new IOException();
                    }
                    return -1;
                }
            };
        }
    };
    EventLoopGroup group = new NioEventLoopGroup(1, new DefaultThreadFactory("ioPool"), SelectorProvider.provider(), selectStrategyFactory);
    final NioEventLoop loop = (NioEventLoop) group.next();
    try {
        Channel channel = new NioServerSocketChannel();
        Selector selector = loop.unwrappedSelector();
        loop.register(channel).syncUninterruptibly();
        Selector newSelector = ((NioEventLoop) channel.eventLoop()).unwrappedSelector();
        assertTrue(newSelector.isOpen());
        assertNotSame(selector, newSelector);
        assertFalse(selector.isOpen());
        channel.close().syncUninterruptibly();
    } finally {
        group.shutdownGracefully();
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) DefaultSelectStrategyFactory(io.netty.channel.DefaultSelectStrategyFactory) SelectStrategyFactory(io.netty.channel.SelectStrategyFactory) EventLoopGroup(io.netty.channel.EventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) IntSupplier(io.netty.util.IntSupplier) SelectStrategy(io.netty.channel.SelectStrategy) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) IOException(java.io.IOException) Selector(java.nio.channels.Selector) AbstractEventLoopTest(io.netty.channel.AbstractEventLoopTest) Test(org.junit.jupiter.api.Test)

Example 4 with SelectStrategyFactory

use of io.netty.channel.SelectStrategyFactory in project netty by netty.

the class EpollEventLoopGroup method newChild.

@Override
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
    Integer maxEvents = (Integer) args[0];
    SelectStrategyFactory selectStrategyFactory = (SelectStrategyFactory) args[1];
    RejectedExecutionHandler rejectedExecutionHandler = (RejectedExecutionHandler) args[2];
    EventLoopTaskQueueFactory taskQueueFactory = null;
    EventLoopTaskQueueFactory tailTaskQueueFactory = null;
    int argsLength = args.length;
    if (argsLength > 3) {
        taskQueueFactory = (EventLoopTaskQueueFactory) args[3];
    }
    if (argsLength > 4) {
        tailTaskQueueFactory = (EventLoopTaskQueueFactory) args[4];
    }
    return new EpollEventLoop(this, executor, maxEvents, selectStrategyFactory.newSelectStrategy(), rejectedExecutionHandler, taskQueueFactory, tailTaskQueueFactory);
}
Also used : EventLoopTaskQueueFactory(io.netty.channel.EventLoopTaskQueueFactory) DefaultSelectStrategyFactory(io.netty.channel.DefaultSelectStrategyFactory) SelectStrategyFactory(io.netty.channel.SelectStrategyFactory) RejectedExecutionHandler(io.netty.util.concurrent.RejectedExecutionHandler)

Aggregations

DefaultSelectStrategyFactory (io.netty.channel.DefaultSelectStrategyFactory)4 SelectStrategyFactory (io.netty.channel.SelectStrategyFactory)4 EventLoopTaskQueueFactory (io.netty.channel.EventLoopTaskQueueFactory)3 RejectedExecutionHandler (io.netty.util.concurrent.RejectedExecutionHandler)3 AbstractEventLoopTest (io.netty.channel.AbstractEventLoopTest)1 Channel (io.netty.channel.Channel)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 SelectStrategy (io.netty.channel.SelectStrategy)1 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 IntSupplier (io.netty.util.IntSupplier)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 IOException (java.io.IOException)1 Selector (java.nio.channels.Selector)1 SocketChannel (java.nio.channels.SocketChannel)1 SelectorProvider (java.nio.channels.spi.SelectorProvider)1 Test (org.junit.jupiter.api.Test)1