Java 类io.netty.channel.epoll.EpollChannelOption 实例源码

项目:nebo    文件:NettyEmbeddedServletContainer.java   
private void groups(ServerBootstrap b) {
    if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
        b.channel(EpollServerSocketChannel.class)
                .group(bossGroup, workerGroup)
                .option(EpollChannelOption.TCP_CORK, true);
    } else {
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
        b.channel(NioServerSocketChannel.class)
                .group(bossGroup, workerGroup);
    }
    b.option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.SO_BACKLOG, 100);
    logger.info("Bootstrap configuration: " + b.toString());
}
项目:voxelwind    文件:McpeOverRakNetNetworkListener.java   
public McpeOverRakNetNetworkListener(VoxelwindServer voxelwindServer, String host, int port, boolean useSoReuseport) {
    this.server = voxelwindServer;
    this.address = new InetSocketAddress(host, port);
    this.useSoReuseport = useSoReuseport;
    if (Epoll.isAvailable()) {
        bootstrap = new Bootstrap()
                .channel(EpollDatagramChannel.class)
                .group(new EpollEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .handler(this);
        if (useSoReuseport) {
            bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        }
    } else {
        bootstrap = new Bootstrap()
                .channel(NioDatagramChannel.class)
                .group(new NioEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .handler(this);
    }
}
项目:spring-boot-starter-netty    文件:NettyEmbeddedServletContainer.java   
private void groups(ServerBootstrap b) {
    if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
        b.channel(EpollServerSocketChannel.class)
                .group(bossGroup, workerGroup)
                .option(EpollChannelOption.TCP_CORK, true);
    } else {
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
        b.channel(NioServerSocketChannel.class)
                .group(bossGroup, workerGroup);
    }
    b.option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.SO_BACKLOG, 100);
    logger.info("Bootstrap configuration: " + b.toString());
}
项目:bgpcep    文件:BGPDispatcherImpl.java   
private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);

    serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);

    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));

    if (serverBootstrap.config().group() == null) {
        serverBootstrap.group(this.bossGroup, this.workerGroup);
    }
    return serverBootstrap;
}
项目:bgpcep    文件:BmpDispatcherUtil.java   
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;
}
项目:bgpcep    文件:PCCDispatcherImpl.java   
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());
        }
    }
}
项目:bgpcep    文件:PCEPDispatcherImpl.java   
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;
}
项目:bgpcep    文件:BGPPeerAcceptorImpl.java   
@Override
public void onPeerAdded(@Nonnull final IpAddress ip, @Nonnull final BGPSessionPreferences prefs) {
    if (prefs.getMd5Password().isPresent()) {
        this.keys.put(IetfInetUtil.INSTANCE.inetAddressFor(ip), prefs.getMd5Password().get());
        this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys);
    }
}
项目:bgpcep    文件:BGPDispatcherImpl.java   
private synchronized Bootstrap createClientBootStrap(final KeyMapping keys, final boolean reuseAddress) {
    final Bootstrap bootstrap = new Bootstrap();
    if (Epoll.isAvailable()) {
        bootstrap.channel(EpollSocketChannel.class);
        bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        bootstrap.channel(NioSocketChannel.class);
    }
    if (keys != null && !keys.isEmpty()) {
        if (Epoll.isAvailable()) {
            bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

    // Make sure we are doing round-robin processing
    bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));
    bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
    bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);
    bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);

    if (bootstrap.config().group() == null) {
        bootstrap.group(this.workerGroup);
    }

    return bootstrap;
}
项目:jooby    文件:NettyServer.java   
@SuppressWarnings("rawtypes")
private Map.Entry<ChannelOption, Class<?>> findOption(final String optionName) {
  try {
    Field field = EpollChannelOption.class.getField(optionName);
    ChannelOption option = (ChannelOption) field.get(null);
    Class optionType = (Class) ((ParameterizedType) field.getGenericType())
      .getActualTypeArguments()[0];
    return Maps.immutableEntry(option, optionType);
  } catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) {
    return null;
  }
}
项目:incubator-pulsar    文件:EventLoopUtil.java   
public static void enableTriggeredMode(ServerBootstrap bootstrap) {
    if (Epoll.isAvailable()) {
        bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    }
}
项目:bgpcep    文件:BmpDispatcherUtil.java   
public static Bootstrap createClientBootstrap(
        @Nonnull final BmpSessionFactory sessionFactory,
        @Nonnull final BmpHandlerFactory hf,
        @Nonnull CreateChannel createChannel,
        @Nonnull final BmpSessionListenerFactory slf,
        @Nonnull final InetSocketAddress remoteAddress,
        @Nullable final SocketAddress localAddress,
        @Nonnull final EventLoopGroup workerGroup,
        final int connectTimeout,
        @Nonnull final KeyMapping keys,
        boolean reuseAddress,
        boolean tryEpollSocket) {
    final Bootstrap bootstrap = new Bootstrap();
    bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout);
    bootstrap.group(workerGroup);
    bootstrap.handler(createChannel.create(sessionFactory, hf, slf));
    if (localAddress != null) {
        bootstrap.localAddress(localAddress);
    }
    bootstrap.remoteAddress(remoteAddress);

    if (!tryEpollSocket) {
        bootstrap.channel(NioSocketChannel.class);

    } else {
        if (Epoll.isAvailable()) {
            bootstrap.channel(EpollSocketChannel.class);
        } else {
            bootstrap.channel(NioSocketChannel.class);
        }
        if (!keys.isEmpty()) {
            if (Epoll.isAvailable()) {
                bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys);
            } else {
                throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
            }
        }
    }
    return bootstrap;
}
项目:bgpcep    文件:BGPPeerAcceptorImpl.java   
@Override
public void onPeerRemoved(@Nonnull final IpAddress ip) {
    if (this.keys.remove(IetfInetUtil.INSTANCE.inetAddressFor(ip)) != null) {
        this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys);
    }
}