java类io.netty.channel.epoll.Epoll的实例源码

TransportTypeHolder.java 文件源码 项目:blynk-server 阅读 20 收藏 0 点赞 0 评论 0
private TransportTypeHolder(int workerThreads) {
    if (Epoll.isAvailable()) {
        log.info("Using native epoll transport.");
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup(workerThreads);
        channelClass = EpollServerSocketChannel.class;
    } else {
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup(workerThreads);
        channelClass = NioServerSocketChannel.class;
    }
}
NodeHealthCheck.java 文件源码 项目:xio 阅读 18 收藏 0 点赞 0 评论 0
public NodeHealthCheck(int workerPoolSize) {
  if (Epoll.isAvailable()) {
    epollEventLoop = new EpollEventLoopGroup(workerPoolSize);
    nioEventLoop = null;
  } else {
    epollEventLoop = null;
    nioEventLoop = new NioEventLoopGroup(workerPoolSize);
  }
}
NetworkManager.java 文件源码 项目:ExpandedRailsMod 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Create a new NetworkManager from the server host and connect it to the server
 */
@SideOnly(Side.CLIENT)
public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && useNativeTransport)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = CLIENT_EPOLL_EVENTLOOP;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(address, serverPort).syncUninterruptibly();
    return networkmanager;
}
BmpDispatcherUtil.java 文件源码 项目:bgpcep 阅读 27 收藏 0 点赞 0 评论 0
public static ServerBootstrap createServerBootstrap(
        @Nonnull final BmpSessionFactory sessionFactory,
        @Nonnull final BmpHandlerFactory hf,
        @Nonnull final BmpSessionListenerFactory slf,
        @Nonnull CreateChannel createChannel,
        @Nonnull final EventLoopGroup bossGroup,
        @Nonnull final EventLoopGroup workerGroup,
        @Nonnull final KeyMapping keys,
        boolean tryEpollSocket) {

    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.childHandler(createChannel.create(sessionFactory, hf, slf));
    serverBootstrap.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.group(bossGroup, workerGroup);

    if (!tryEpollSocket) {
        serverBootstrap.channel(NioServerSocketChannel.class);
    } else {
        if (Epoll.isAvailable()) {
            serverBootstrap.channel(EpollServerSocketChannel.class);
        } else {
            serverBootstrap.channel(NioServerSocketChannel.class);
        }

        if (!keys.isEmpty()) {
            if (Epoll.isAvailable()) {
                serverBootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
            } else {
                throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
            }
        }
    }

    return serverBootstrap;
}
BmpDispatcherImpl.java 文件源码 项目:bgpcep 阅读 23 收藏 0 点赞 0 评论 0
public BmpDispatcherImpl(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
        final BmpMessageRegistry registry, final BmpSessionFactory sessionFactory) {
    if (Epoll.isAvailable()) {
        this.bossGroup = new EpollEventLoopGroup();
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.bossGroup = requireNonNull(bossGroup);
        this.workerGroup = requireNonNull(workerGroup);
    }
    this.hf = new BmpHandlerFactory(requireNonNull(registry));
    this.sessionFactory = requireNonNull(sessionFactory);
}
BmpDispatcherImpl.java 文件源码 项目:bgpcep 阅读 18 收藏 0 点赞 0 评论 0
@Override
public synchronized void close() {
    this.close = true;
    if (Epoll.isAvailable()) {
        this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
        this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
    }
}
PCCDispatcherImpl.java 文件源码 项目:bgpcep 阅读 22 收藏 0 点赞 0 评论 0
public PCCDispatcherImpl(@Nonnull final MessageRegistry registry) {
    if (Epoll.isAvailable()) {
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.workerGroup = new NioEventLoopGroup();
    }
    this.factory = new PCEPHandlerFactory(registry);
}
PCCDispatcherImpl.java 文件源码 项目:bgpcep 阅读 28 收藏 0 点赞 0 评论 0
private static void setChannelFactory(final Bootstrap bootstrap, final KeyMapping keys) {
    if (Epoll.isAvailable()) {
        bootstrap.channel(EpollSocketChannel.class);
        bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        bootstrap.channel(NioSocketChannel.class);
    }
    if (!keys.isEmpty()) {
        if (Epoll.isAvailable()) {
            bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
}
PCEPDispatcherImpl.java 文件源码 项目:bgpcep 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
 *
 * @param registry          a message registry
 * @param negotiatorFactory a negotiation factory
 * @param bossGroup         accepts an incoming connection
 * @param workerGroup       handles the traffic of accepted connection
 */
public PCEPDispatcherImpl(@Nonnull final MessageRegistry registry,
        @Nonnull final PCEPSessionNegotiatorFactory<PCEPSessionImpl> negotiatorFactory,
        @Nonnull final EventLoopGroup bossGroup, @Nonnull final EventLoopGroup workerGroup) {
    this.snf = requireNonNull(negotiatorFactory);
    this.hf = new PCEPHandlerFactory(registry);
    if (Epoll.isAvailable()) {
        this.bossGroup = new EpollEventLoopGroup();
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.bossGroup = requireNonNull(bossGroup);
        this.workerGroup = requireNonNull(workerGroup);
    }
    this.executor = requireNonNull(GlobalEventExecutor.INSTANCE);
}
PCEPDispatcherImpl.java 文件源码 项目:bgpcep 阅读 28 收藏 0 点赞 0 评论 0
synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(final SocketChannel ch) {
            initializer.initializeChannel(ch, new DefaultPromise<>(PCEPDispatcherImpl.this.executor));
        }
    });
    b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);

    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
        b.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        b.channel(NioServerSocketChannel.class);
    }
    if (!this.keys.isEmpty()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, this.keys);
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

    // Make sure we are doing round-robin processing
    b.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1));

    if (b.config().group() == null) {
        b.group(this.bossGroup, this.workerGroup);
    }

    return b;
}


问题


面经


文章

微信
公众号

扫码关注公众号