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

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

Introduction

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

Prototype

public static Throwable unavailabilityCause() 

Source Link

Document

Returns the cause of unavailability of <a href="https://netty.io/wiki/native-transports.html"> netty-transport-native-epoll </a>.

Usage

From source file:com.linecorp.armeria.common.util.NativeLibraries.java

License:Apache License

/**
 * Logs the availability of the native libraries used by Armeria. This method does nothing if it was
 * called once before./*ww  w  . j  a va2s.  c o  m*/
 */
public static void report() {
    if (!reported.compareAndSet(false, true)) {
        return;
    }

    if (USE_EPOLL) {
        logger.info("/dev/epoll: "
                + (Epoll.isAvailable() ? "yes" : "no (" + filterCause(Epoll.unavailabilityCause()) + ')'));
    } else {
        logger.info("/dev/epoll: disabled");
    }

    if (USE_OPENSSL) {
        logger.info("OpenSSL: "
                + (OpenSsl.isAvailable() ? "yes (" + OpenSsl.versionString() + ", " + OpenSsl.version() + ')'
                        : "no (" + filterCause(OpenSsl.unavailabilityCause()) + ')'));
    } else {
        logger.info("OpenSSL: disabled");
    }
}

From source file:io.vertx.core.net.impl.transport.EpollTransport.java

License:Open Source License

@Override
public Throwable unavailabilityCause() {
    return Epoll.unavailabilityCause();
}

From source file:org.lanternpowered.pingy.Pingy.java

License:MIT License

/**
 * Starts the pingy server./*w  w w .  j  a v a2  s.  c  o m*/
 *
 * @throws IOException
 */
public void start() throws IOException {
    boolean epoll = false;

    if (this.properties.isUseEpollWhenAvailable()) {
        if (Epoll.isAvailable()) {
            debugInfo("Epoll is available");
            epoll = true;
        } else {
            debugWarn(
                    "Epoll is unavailable (The following exception is only used to print the cause why it's unavailable, "
                            + "it won't affect the functionality.)");
            //noinspection ThrowableResultOfMethodCallIgnored
            debug(() -> Epoll.unavailabilityCause().printStackTrace());
        }
    }

    final ServerBootstrap bootstrap = new ServerBootstrap();
    final EventLoopGroup group = epoll ? new EpollEventLoopGroup() : new NioEventLoopGroup();

    final ChannelFuture future = bootstrap.group(group)
            .channel(epoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new ReadTimeoutHandler(20))
                            .addLast(new PingyLegacyHandler(properties)).addLast(new PingyFramingHandler())
                            .addLast(new PingyHandler(properties));
                }
            }).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true)
            .bind(getBindAddress(this.properties.getIp(), this.properties.getPort()));
    final Channel channel = future.awaitUninterruptibly().channel();
    if (!channel.isActive()) {
        final Throwable cause = future.cause();
        if (cause instanceof BindException) {
            throw (BindException) cause;
        }
        throw new RuntimeException("Failed to bind to address", cause);
    }
    info("Successfully bound to: " + channel.localAddress());
}

From source file:org.lanternpowered.server.network.ServerBase.java

License:MIT License

/**
 * Initializes the network server./* w w w  .j  a  va2  s  .  c o  m*/
 *
 * @param address The address to bind the server to
 * @param useEpollWhenAvailable Whether you want to use epoll if it's available
 * @return The channel future
 */
public final ChannelFuture init(SocketAddress address, boolean useEpollWhenAvailable) {
    if (this.initialized) {
        throw new IllegalStateException("The network server can only be initialized once.");
    }
    boolean epoll = false;
    if (epollAvailabilityLogged) {
        epoll = Epoll.isAvailable() && useEpollWhenAvailable;
    } else if (useEpollWhenAvailable) {
        if (Epoll.isAvailable()) {
            epoll = true;
            Lantern.getLogger().info("Epoll is enabled.");
        } else {
            // Debug the reason why it is unavailable
            Lantern.getLogger().debug("Epoll is unavailable.", Epoll.unavailabilityCause());
        }
        epollAvailabilityLogged = true;
    }
    final ChannelFuture future = init0(address, epoll);
    this.initialized = true;
    return future;
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java

License:Open Source License

protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) {
    final Bootstrap bootstrap = new Bootstrap();
    if (Epoll.isAvailable()) {
        bootstrap.channel(EpollSocketChannel.class);
        bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {//from  w  w  w.ja v  a2 s  .c o  m
        bootstrap.channel(NioSocketChannel.class);
    }
    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

    // Make sure we are doing round-robin processing
    bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
    bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
    bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);

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

    return bootstrap;
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createClient(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {

    final Bootstrap b = new Bootstrap();

    Preconditions.checkNotNull(address);

    if (Epoll.isAvailable()) {
        b.channel(EpollSocketChannel.class);
    } else {//from   w  ww  .ja  v  a2s.com
        b.channel(NioSocketChannel.class);
    }
    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT);
    b.group(this.workerGroup);

    b.handler(new ChannelInitializer<AbstractChannel>() {
        @Override
        protected void initChannel(final AbstractChannel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.remoteAddress(address);
    final ChannelFuture channelPromise = b.connect();
    channelPromise.addListener(new BmpDispatcherImpl.BootstrapListener(b, address));
    return channelPromise;
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createServer(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {
    Preconditions.checkNotNull(address);
    Preconditions.checkNotNull(slf);/*w  w w.  j  av a2s. c o m*/

    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

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

    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.group(this.bossGroup, this.workerGroup);
    final ChannelFuture f = b.bind(address);

    LOG.debug("Initiated BMP server {} at {}.", f, address);
    return f;
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl.java

License:Open Source License

protected ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override//ww  w .  j  a v  a  2  s.  co m
        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.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, this.keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

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

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

    return b;
}

From source file:org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl.java

License:Open Source License

private void setChannelFactory(final Bootstrap bootstrap, final Optional<KeyMapping> keys) {
    if (Epoll.isAvailable()) {
        bootstrap.channel(EpollSocketChannel.class);
        bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {/*from   w  w  w.  j  a v a  2 s.co m*/
        bootstrap.channel(NioSocketChannel.class);
    }
    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
}

From source file:org.opendaylight.sxp.core.service.ConnectFacade.java

License:Open Source License

/**
 * Create new Connection to Peer/* www . j ava 2 s  .c  o  m*/
 *
 * @param node       SxpNode containing Security options
 * @param connection SxpConnection containing connection details
 * @param hf         HandlerFactory providing handling of communication
 * @return ChannelFuture callback
 */
public static ChannelFuture createClient(SxpNode node, SxpConnection connection, final HandlerFactory hf) {
    if (!Epoll.isAvailable()) {
        throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
    }
    Bootstrap bootstrap = new Bootstrap();
    if (connection.getPassword() != null && !connection.getPassword().isEmpty()) {
        bootstrap.option(EpollChannelOption.TCP_MD5SIG,
                Collections.singletonMap(connection.getDestination().getAddress(),
                        connection.getPassword().getBytes(StandardCharsets.US_ASCII)));
    }
    bootstrap.channel(EpollSocketChannel.class);
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Configuration.NETTY_CONNECT_TIMEOUT_MILLIS);
    RecvByteBufAllocator recvByteBufAllocator = new FixedRecvByteBufAllocator(
            Configuration.getConstants().getMessageLengthMax());
    bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.localAddress(node.getSourceIp().getHostAddress(), 0);
    bootstrap.group(eventLoopGroup);
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast(hf.getEncoders());
        }
    });
    return bootstrap.connect(connection.getDestination());
}