Example usage for io.netty.channel.epoll Epoll isAvailable

List of usage examples for io.netty.channel.epoll Epoll isAvailable

Introduction

In this page you can find the example usage for io.netty.channel.epoll Epoll isAvailable.

Prototype

public static boolean isAvailable() 

Source Link

Document

Returns true if and only if the <a href="https://netty.io/wiki/native-transports.html"> netty-transport-native-epoll </a> is available.

Usage

From source file:alluxio.network.ChannelType.java

License:Apache License

/**
 * Determines the default type to use based off the system.
 * <p>// ww  w  . j  a  va2  s.com
 * On Linux-based systems, {@link #EPOLL} is the default type for more consistent performance,
 * otherwise {@link #NIO}.
 * </p>
 *
 * @return a {@link ChannelType} compatible with the host
 */
public static ChannelType defaultType() {
    if (Epoll.isAvailable()) {
        return ChannelType.EPOLL;
    } else {
        return ChannelType.NIO;
    }
}

From source file:com.ancun.netty.common.NettyBootstrapFactory.java

License:Apache License

/**
 * netty http??/*  w  ww .  java2  s  .c  om*/
 *
 * @param ioThreadCount   IO
 * @return   netty http??
  */
public ServerBootstrap newServerBootstrap(int ioThreadCount) {
    if (Epoll.isAvailable()) {
        return newEpollServerBootstrap(ioThreadCount);
    }

    return newNioServerBootstrap(ioThreadCount);
}

From source file:com.ancun.netty.common.NettyBootstrapFactory.java

License:Apache License

/**
 * netty http?//  ww w.  j a  v  a 2  s . c  om
 *
 * @return   netty http?
 */
public Bootstrap newClientBootstrap() {

    if (Epoll.isAvailable()) {
        return newEpollClientBootstrap();
    }

    return newNioClientBootstrap();
}

From source file:com.caricah.iotracah.server.netty.ServerImpl.java

License:Apache License

/**
 * The @link configure method is responsible for starting the implementation server processes.
 * The implementation should return once the server has started this allows
 * the launcher to maintain the life of the application.
 *
 * @throws UnRetriableException//from w  w w .j  av  a 2s. c  o  m
 */
public void initiate() throws UnRetriableException {

    log.info(" configure : initiating the netty server.");

    try {

        int countOfAvailableProcessors = Runtime.getRuntime().availableProcessors() + 1;

        if (Epoll.isAvailable()) {
            bossEventLoopGroup = new EpollEventLoopGroup(2, getExecutorService());
            workerEventLoopGroup = new EpollEventLoopGroup(countOfAvailableProcessors, getExecutorService());

        } else {
            bossEventLoopGroup = new NioEventLoopGroup(2, getExecutorService());
            workerEventLoopGroup = new NioEventLoopGroup(countOfAvailableProcessors, getExecutorService());
        }

        //Initialize listener for TCP
        ServerBootstrap tcpBootstrap = new ServerBootstrap();
        tcpBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
        tcpBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
        tcpBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);

        tcpBootstrap = tcpBootstrap.group(bossEventLoopGroup, workerEventLoopGroup);

        if (Epoll.isAvailable()) {
            tcpBootstrap = tcpBootstrap.channel(EpollServerSocketChannel.class);
        } else {
            tcpBootstrap = tcpBootstrap.channel(NioServerSocketChannel.class);
        }

        tcpBootstrap = tcpBootstrap.handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(getServerInitializer(this, getConnectionTimeout()));

        ChannelFuture tcpChannelFuture = tcpBootstrap.bind(getTcpPort()).sync();
        tcpChannel = tcpChannelFuture.channel();

        if (isSslEnabled()) {
            //Initialize listener for SSL
            ServerBootstrap sslBootstrap = new ServerBootstrap();
            sslBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
            sslBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
            sslBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);

            sslBootstrap = sslBootstrap.group(bossEventLoopGroup, workerEventLoopGroup);

            if (Epoll.isAvailable()) {
                sslBootstrap = sslBootstrap.channel(EpollServerSocketChannel.class);
            } else {
                sslBootstrap = sslBootstrap.channel(NioServerSocketChannel.class);
            }

            sslBootstrap = sslBootstrap.handler(new LoggingHandler(LogLevel.INFO))
                    .childHandler(getServerInitializer(this, getConnectionTimeout(), getSslHandler()));

            ChannelFuture sslChannelFuture = sslBootstrap.bind(getSslPort()).sync();
            sslChannel = sslChannelFuture.channel();
        }

    } catch (InterruptedException e) {

        log.error(" configure : Initialization issues ", e);

        throw new UnRetriableException(e);

    }

}

From source file:com.codahale.grpcproxy.util.Netty.java

License:Apache License

public static EventLoopGroup newBossEventLoopGroup() {
    if (Epoll.isAvailable()) {
        return new EpollEventLoopGroup();
    }/*  w  w  w.  j a v  a2s .c o  m*/
    return new NioEventLoopGroup();
}

From source file:com.codahale.grpcproxy.util.Netty.java

License:Apache License

public static EventLoopGroup newWorkerEventLoopGroup() {
    if (Epoll.isAvailable()) {
        return new EpollEventLoopGroup(WORKER_THREADS);
    }/*from  w  w w.  jav  a  2  s.com*/
    return new NioEventLoopGroup(WORKER_THREADS);
}

From source file:com.codahale.grpcproxy.util.Netty.java

License:Apache License

public static Class<? extends ServerChannel> serverChannelType() {
    if (Epoll.isAvailable()) {
        return EpollServerSocketChannel.class;
    }//from  w  w w  .ja  va 2s . c o m
    return NioServerSocketChannel.class;
}

From source file:com.codahale.grpcproxy.util.Netty.java

License:Apache License

public static Class<? extends Channel> clientChannelType() {
    if (Epoll.isAvailable()) {
        return EpollSocketChannel.class;
    }/*  w  ww .  ja  v a 2 s .co  m*/
    return NioSocketChannel.class;
}

From source file:com.github.thinker0.mesos.MesosHealthCheckerServer.java

License:Apache License

/**
 * Starts the web server.//from   ww  w  .j av a2  s.  co m
 *
 * @throws Exception
 */
public EventLoopGroup start() throws Exception {
    if (Epoll.isAvailable()) {
        eventLoopGroup = new EpollEventLoopGroup();
        start(new EpollEventLoopGroup(), EpollServerSocketChannel.class);
    } else {
        eventLoopGroup = new NioEventLoopGroup();
        start(new NioEventLoopGroup(), NioServerSocketChannel.class);
    }
    return eventLoopGroup;
}

From source file:com.ibasco.agql.core.enums.ChannelType.java

License:Open Source License

public Class<? extends Channel> getChannelClass() {
    if (Epoll.isAvailable()) {
        if (NioSocketChannel.class.equals(channelClass)) {
            log.debug("Using EpollSocketChannel");
            return EpollSocketChannel.class;
        } else if (NioDatagramChannel.class.equals(channelClass)) {
            log.debug("Using EpollDatagramChannel");
            return EpollDatagramChannel.class;
        }/*from ww  w .j  a  v  a2  s .  c o  m*/
    }
    log.debug("Epoll not available. Falling back to {}", channelClass);
    return channelClass;
}