io.netty.channel.epoll.Epoll Java Examples

The following examples show how to use io.netty.channel.epoll.Epoll. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsyncHttpService.java    From arcusplatform with Apache License 2.0 7 votes vote down vote up
static void start() {
   final AtomicLong counter = new AtomicLong();
   ThreadFactory tf = new ThreadFactory() {
      @Override
      public Thread newThread(@Nullable Runnable runnable) {
         Thread thr = new Thread(runnable);
         thr.setName("ahc" + counter.getAndIncrement());
         thr.setDaemon(true);
         return thr;
      }
   };

   useEpoll = Epoll.isAvailable();
   useOpenSsl = false;

   evlg = useEpoll ? new EpollEventLoopGroup(2,tf) : new NioEventLoopGroup(2,tf);

   DefaultAsyncHttpClientConfig config = builder().build();
   client = new DefaultAsyncHttpClient(config);
}
 
Example #2
Source File: AbstractBGPDispatcherTest.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() {
    if (!Epoll.isAvailable()) {
        this.boss = new NioEventLoopGroup();
        this.worker = new NioEventLoopGroup();
    }
    this.registry = new StrictBGPPeerRegistry();
    this.clientListener = new SimpleSessionListener();
    this.serverListener = new SimpleSessionListener();
    final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
    this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);

    this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
    final IpAddressNoZone clientPeerIp = new IpAddressNoZone(new Ipv4AddressNoZone(
        this.clientAddress.getAddress().getHostAddress()));
    this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
    this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
}
 
Example #3
Source File: GoogleAuthUtils.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static NettyChannelBuilder newNettyChannelBuilder(String targetUrl, String proxy)
    throws IOException {
  if (Strings.isNullOrEmpty(proxy)) {
    return NettyChannelBuilder.forTarget(targetUrl).defaultLoadBalancingPolicy("round_robin");
  }

  if (!proxy.startsWith("unix:")) {
    throw new IOException("Remote proxy unsupported: " + proxy);
  }

  DomainSocketAddress address = new DomainSocketAddress(proxy.replaceFirst("^unix:", ""));
  NettyChannelBuilder builder =
      NettyChannelBuilder.forAddress(address).overrideAuthority(targetUrl);
  if (KQueue.isAvailable()) {
    return builder
        .channelType(KQueueDomainSocketChannel.class)
        .eventLoopGroup(new KQueueEventLoopGroup());
  }
  if (Epoll.isAvailable()) {
    return builder
        .channelType(EpollDomainSocketChannel.class)
        .eventLoopGroup(new EpollEventLoopGroup());
  }

  throw new IOException("Unix domain sockets are unsupported on this platform");
}
 
Example #4
Source File: UDPServerSocket.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public UDPServerSocket(ThreadedLogger logger, int port, String interfaz) {
    this.logger = logger;
    try {
        if (Epoll.isAvailable()) {
            bootstrap = new Bootstrap()
                    .channel(EpollDatagramChannel.class)
                    .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                    .handler(this)
                    .group(new EpollEventLoopGroup());
            this.logger.info("Epoll is available. EpollEventLoop will be used.");
        } else {
            bootstrap = new Bootstrap()
                    .group(new NioEventLoopGroup())
                    .channel(NioDatagramChannel.class)
                    .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                    .handler(this);
            this.logger.info("Epoll is unavailable. Reverting to NioEventLoop.");
        }
        channel = bootstrap.bind(interfaz, port).sync().channel();
    } catch (Exception e) {
        this.logger.critical("**** FAILED TO BIND TO " + interfaz + ":" + port + "!");
        this.logger.critical("Perhaps a server is already running on that port?");
        System.exit(1);
    }
}
 
Example #5
Source File: Settings.java    From kyoko with MIT License 6 votes vote down vote up
@JsonIgnore
public Config configureRedis() throws URISyntaxException {
    var redisConfig = new Config();
    var redis = new URI(Settings.instance().redisUrl());
    if (!redis.getScheme().equals("redis") && !redis.getScheme().equals("rediss")) {
        throw new IllegalArgumentException("Invalid scheme for Redis connection URI!");
    }

    var database = redis.getPath() == null || redis.getPath().isBlank() ? 0
            : Integer.parseUnsignedInt(redis.getPath().substring(1));

    redisConfig.setTransportMode(Epoll.isAvailable() ? TransportMode.EPOLL : TransportMode.NIO);
    redisConfig.setNettyThreads(16);
    redisConfig.useSingleServer()
            .setAddress(redis.getScheme() + "://"
                    + requireNonNullElse(redis.getHost(), "localhost") + ":"
                    + requireNonNullElse(redis.getPort(), 6379))
            .setDatabase(database)
            .setPassword(redis.getUserInfo());

    return redisConfig;
}
 
Example #6
Source File: KMSEncryptionProvider.java    From credhub with Apache License 2.0 6 votes vote down vote up
private void setChannelInfo() {
  if (Epoll.isAvailable()) {
    this.group = new EpollEventLoopGroup();
    this.channelType = EpollDomainSocketChannel.class;
    LOGGER.info("Using epoll for Netty transport.");
  } else {
    if (!KQueue.isAvailable()) {
      throw new RuntimeException("Unsupported OS '" + System.getProperty("os.name") + "', only Unix and Mac are supported");
    }

    this.group = new KQueueEventLoopGroup();
    this.channelType = KQueueDomainSocketChannel.class;
    LOGGER.info("Using KQueue for Netty transport.");
  }

}
 
Example #7
Source File: GatewayNetty.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static Provider create() {
   Supplier<String> nettyProvider = ConfigService.supplier("iris.gateway.provider", String.class, "");
   switch (nettyProvider.get()) {
   case "epoll":
      if (Epoll.isAvailable()) {
         log.debug("using netty epoll provider for gateway connection");
         return epoll();
      } else {
         if (!"".equals(nettyProvider.get())) {
            log.warn("netty epoll provider requested but not available, using nio for gateway connection:", Epoll.unavailabilityCause());
         } else {
            log.debug("using netty nio provider for gateway connection");
         }
         return nio();
      }

   case "":
   case "nio":
      log.debug("using netty nio provider for gateway connection");
      return nio();

   default:
      log.warn("unknown netty provider, using nio by default");
      return nio();
   }
}
 
Example #8
Source File: TransportServerSupport.java    From joyqueue with Apache License 2.0 6 votes vote down vote up
protected ServerBootstrap newBootstrap(ChannelHandler channelHandler, EventLoopGroup acceptEventGroup, EventLoopGroup ioEventGroup) throws Exception {
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .group(acceptEventGroup, ioEventGroup)
            .childHandler(channelHandler)
            .option(ChannelOption.SO_REUSEADDR, config.isReuseAddress())
            .option(ChannelOption.SO_RCVBUF, config.getSocketBufferSize())
            .option(ChannelOption.SO_BACKLOG, config.getBacklog())
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .childOption(ChannelOption.SO_SNDBUF, config.getSocketBufferSize())
            .childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay())
            .childOption(ChannelOption.SO_KEEPALIVE, config.isKeepAlive())
            .childOption(ChannelOption.SO_LINGER, config.getSoLinger())
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    return serverBootstrap;
}
 
Example #9
Source File: UdpServerChannel.java    From UdpServerSocketChannel with GNU Lesser General Public License v3.0 6 votes vote down vote up
public UdpServerChannel(int ioThreads) {
	if (ioThreads < 1) {
		throw new IllegalArgumentException("IO threads cound can't be less than 1");
	}
	boolean epollAvailabe = Epoll.isAvailable();
	if (!epollAvailabe) {
		ioThreads = 1;
	}
	group = epollAvailabe ? new EpollEventLoopGroup(ioThreads) : new NioEventLoopGroup(ioThreads);
	Class<? extends DatagramChannel> channel = epollAvailabe ? EpollDatagramChannel.class : NioDatagramChannel.class;
	ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {
		final ReadRouteChannelHandler ioReadRoute = new ReadRouteChannelHandler();
		@Override
		protected void initChannel(Channel ioChannel) throws Exception {
			ioChannel.pipeline().addLast(ioReadRoute);
		}
	};
	while (ioThreads-- > 0) {
		Bootstrap ioBootstrap = new Bootstrap().group(group).channel(channel).handler(initializer);
		if (epollAvailabe) {
			ioBootstrap.option(UnixChannelOption.SO_REUSEPORT, true);
		}
		ioBootstraps.add(ioBootstrap);
	}
}
 
Example #10
Source File: NettyExecutor.java    From styx with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an netty/io event executor.
 *
 * @param name  thread group name.
 * @param count thread count.
 * @return
 */
public static NettyExecutor create(String name, int count) {
    if (Epoll.isAvailable()) {
        LOG.info("Epoll is available. Using the native socket transport.");
        return new NettyExecutor(
                epollEventLoopGroup(count, name + "-%d-Thread"),
                EpollServerSocketChannel.class,
                EpollSocketChannel.class);
    } else {
        LOG.info("Epoll not available. Using nio socket transport.");
        return new NettyExecutor(
                nioEventLoopGroup(count, name + "-%d-Thread"),
                NioServerSocketChannel.class,
                NioSocketChannel.class);
    }
}
 
Example #11
Source File: HttpCacheClientTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Parameters
public static Collection createInputValues() {
  ArrayList<Object[]> parameters =
      new ArrayList<Object[]>(Arrays.asList(new Object[][] {{new InetTestServer()}}));

  if (Epoll.isAvailable()) {
    parameters.add(
        new Object[] {
          new UnixDomainServer(EpollServerDomainSocketChannel.class, EpollEventLoopGroup::new)
        });
  }

  if (KQueue.isAvailable()) {
    parameters.add(
        new Object[] {
          new UnixDomainServer(KQueueServerDomainSocketChannel.class, KQueueEventLoopGroup::new)
        });
  }

  return parameters;
}
 
Example #12
Source File: VoiceWebsocket.java    From kyoko with MIT License 6 votes vote down vote up
private CompletableFuture<Bootstrap> setupNetty(InetSocketAddress address, ChannelHandler handler) {
    var future = new CompletableFuture<Bootstrap>();

    var bootstrap = new Bootstrap()
            .group(vertx.nettyEventLoopGroup());

    if (Epoll.isAvailable()) {
        logger.info("epoll support is available, using it for UDP connections.");
        bootstrap.channel(EpollDatagramChannel.class);
    } else {
        logger.info("epoll unavailable, falling back to NIO.");
        bootstrap.channel(NioDatagramChannel.class);
    }

    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.option(ChannelOption.IP_TOS, 0x10 | 0x08); // IPTOS_LOWDELAY | IPTOS_THROUGHPUT
    bootstrap.handler(handler).connect(address).addListener(res -> {
        if (res.isSuccess()) {
            future.complete(bootstrap);
        } else {
            future.completeExceptionally(res.cause());
        }
    });

    return future;
}
 
Example #13
Source File: MusServer.java    From Kepler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create the Netty sockets.
 */
public void createSocket() {
    int threads = Runtime.getRuntime().availableProcessors();
    this.bossGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads);
    this.workerGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads);

    this.bootstrap.group(bossGroup, workerGroup)
            .channel((Epoll.isAvailable()) ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .childHandler(new MusChannelInitializer(this))
            .option(ChannelOption.SO_BACKLOG, BACK_LOG)
            .childOption(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.SO_KEEPALIVE, true)
            .childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE)
            .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(BUFFER_SIZE))
            .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true));
}
 
Example #14
Source File: NettyServer.java    From Kepler with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create the Netty sockets.
 */
public void createSocket() {
    int threads = Runtime.getRuntime().availableProcessors();
    this.bossGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads);
    this.workerGroup = (Epoll.isAvailable()) ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads);

    this.bootstrap.group(bossGroup, workerGroup)
            .channel((Epoll.isAvailable()) ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .childHandler(new NettyChannelInitializer(this))
            .option(ChannelOption.SO_BACKLOG, BACK_LOG)
            .childOption(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.SO_KEEPALIVE, true)
            .childOption(ChannelOption.SO_RCVBUF, BUFFER_SIZE)
            .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(BUFFER_SIZE))
            .childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true));
}
 
Example #15
Source File: HttpCacheClient.java    From bazel with Apache License 2.0 5 votes vote down vote up
public static HttpCacheClient create(
    DomainSocketAddress domainSocketAddress,
    URI uri,
    int timeoutSeconds,
    int remoteMaxConnections,
    boolean verifyDownloads,
    ImmutableList<Entry<String, String>> extraHttpHeaders,
    DigestUtil digestUtil,
    @Nullable final Credentials creds)
    throws Exception {

  if (KQueue.isAvailable()) {
    return new HttpCacheClient(
        KQueueEventLoopGroup::new,
        KQueueDomainSocketChannel.class,
        uri,
        timeoutSeconds,
        remoteMaxConnections,
        verifyDownloads,
        extraHttpHeaders,
        digestUtil,
        creds,
        domainSocketAddress);
  } else if (Epoll.isAvailable()) {
    return new HttpCacheClient(
        EpollEventLoopGroup::new,
        EpollDomainSocketChannel.class,
        uri,
        timeoutSeconds,
        remoteMaxConnections,
        verifyDownloads,
        extraHttpHeaders,
        digestUtil,
        creds,
        domainSocketAddress);
  } else {
    throw new Exception("Unix domain sockets are unsupported on this platform");
  }
}
 
Example #16
Source File: FlagsTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Makes sure /dev/epoll is used while running tests on Linux.
 */
@Test
void epollAvailableOnLinux() {
    assumeThat(osName).startsWith("linux");
    assumeThat(System.getenv("WSLENV")).isNull();
    assumeThat(System.getProperty("com.linecorp.armeria.useEpoll")).isEqualTo("false");

    assertThat(Flags.useEpoll()).isTrue();
    assertThat(Epoll.isAvailable()).isTrue();
}
 
Example #17
Source File: EventLoopUtil.java    From pulsar with Apache License 2.0 5 votes vote down vote up
/**
 * @return an EventLoopGroup suitable for the current platform
 */
public static EventLoopGroup newEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
    if (Epoll.isAvailable()) {
        return new EpollEventLoopGroup(nThreads, threadFactory);
    } else {
        // Fallback to NIO
        return new NioEventLoopGroup(nThreads, threadFactory);
    }
}
 
Example #18
Source File: Flags.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static boolean isEpollAvailable() {
    if (SystemInfo.isLinux()) {
        // Netty epoll transport does not work with WSL (Windows Sybsystem for Linux) yet.
        // TODO(trustin): Re-enable on WSL if https://github.com/Microsoft/WSL/issues/1982 is resolved.
        return Epoll.isAvailable() && !HAS_WSLENV;
    }
    return false;
}
 
Example #19
Source File: PCEPDispatcherImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #20
Source File: HttpBlobStore.java    From bazel-buildfarm with Apache License 2.0 5 votes vote down vote up
public static HttpBlobStore create(
    DomainSocketAddress domainSocketAddress,
    URI uri,
    int timeoutMillis,
    int remoteMaxConnections,
    @Nullable final Credentials creds)
    throws ConfigurationException, URISyntaxException, SSLException {

  if (KQueue.isAvailable()) {
    return new HttpBlobStore(
        KQueueEventLoopGroup::new,
        KQueueDomainSocketChannel.class,
        uri,
        timeoutMillis,
        remoteMaxConnections,
        creds,
        domainSocketAddress);
  } else if (Epoll.isAvailable()) {
    return new HttpBlobStore(
        EpollEventLoopGroup::new,
        EpollDomainSocketChannel.class,
        uri,
        timeoutMillis,
        remoteMaxConnections,
        creds,
        domainSocketAddress);
  } else {
    throw new ConfigurationException("Unix domain sockets are unsupported on this platform");
  }
}
 
Example #21
Source File: BGPPeerAcceptorImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public void start() {
    LOG.debug("Instantiating BGP Peer Acceptor : {}", this.address);

    this.futureChannel = this.bgpDispatcher.createServer(this.address);
    // Validate future success
    this.futureChannel.addListener(future -> {
        Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s",
            this.address, future.cause());
        final Channel channel = this.futureChannel.channel();
        if (Epoll.isAvailable()) {
            this.listenerRegistration = this.bgpDispatcher.getBGPPeerRegistry().registerPeerRegisterListener(
                new BGPPeerAcceptorImpl.PeerRegistryListenerImpl(channel.config()));
        }
    });
}
 
Example #22
Source File: Connector.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
public Class<? extends Channel> getClientChannel() {
    if (useNativeIo && Epoll.isAvailable()) {
        return uds ? EpollDomainSocketChannel.class : EpollSocketChannel.class;
    } else if (useNativeIo && KQueue.isAvailable()) {
        return uds ? KQueueDomainSocketChannel.class : KQueueSocketChannel.class;
    }

    return NioSocketChannel.class;
}
 
Example #23
Source File: CheckDependencies.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static final boolean isEpollAvailable() {
   try {
      return Env.isLinuxOs() && Epoll.isAvailable();
   } catch (NoClassDefFoundError noClassDefFoundError) {
      ActiveMQClientLogger.LOGGER.unableToCheckEpollAvailabilitynoClass();
      return false;
   } catch (Throwable e)  {
      ActiveMQClientLogger.LOGGER.unableToCheckEpollAvailability(e);
      return false;
   }
}
 
Example #24
Source File: Connector.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
public static EventLoopGroup newEventLoopGroup(int threads) {
    if (useNativeIo && Epoll.isAvailable()) {
        return new EpollEventLoopGroup(threads);
    } else if (useNativeIo && KQueue.isAvailable()) {
        return new KQueueEventLoopGroup(threads);
    }

    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(threads);
    eventLoopGroup.setIoRatio(ConfigManager.getInstance().getIoRatio());
    return eventLoopGroup;
}
 
Example #25
Source File: BGPDispatcherImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup,
        final EventLoopGroup workerGroup, final BGPPeerRegistry bgpPeerRegistry) {
    if (Epoll.isAvailable()) {
        this.bossGroup = new EpollEventLoopGroup();
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.bossGroup = requireNonNull(bossGroup);
        this.workerGroup = requireNonNull(workerGroup);
    }
    this.bgpPeerRegistry = requireNonNull(bgpPeerRegistry);
    this.handlerFactory = new BGPHandlerFactory(messageRegistry);
}
 
Example #26
Source File: BmpDispatcherUtil.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public static ServerBootstrap createServerBootstrap(final @NonNull BmpSessionFactory sessionFactory,
        final @NonNull BmpHandlerFactory hf, final @NonNull BmpSessionListenerFactory slf,
        final @NonNull CreateChannel createChannel, final @NonNull EventLoopGroup bossGroup,
        final @NonNull EventLoopGroup workerGroup, final @NonNull 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;
}
 
Example #27
Source File: BmpDispatcherUtil.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public static Bootstrap createClientBootstrap(final @NonNull BmpSessionFactory sessionFactory,
        final @NonNull BmpHandlerFactory hf, final @NonNull CreateChannel createChannel,
        final @NonNull BmpSessionListenerFactory slf, final @NonNull InetSocketAddress remoteAddress,
        final @Nullable SocketAddress localAddress, final @NonNull EventLoopGroup workerGroup,
        final int connectTimeout, final @NonNull 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;
}
 
Example #28
Source File: BmpDispatcherImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
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);
}
 
Example #29
Source File: EpollSupport.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public static boolean isAvailable(TransportOptions transportOptions) {
    try {
        return transportOptions.isUseEpoll() && Epoll.isAvailable();
    } catch (NoClassDefFoundError ncdfe) {
        LOG.debug("Unable to check for Epoll support due to missing class definition", ncdfe);
        return false;
    }
}
 
Example #30
Source File: XdsClientWrapperForServerSds.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public ScheduledExecutorService create() {
  // Use Netty's DefaultThreadFactory in order to get the benefit of FastThreadLocal.
  ThreadFactory threadFactory = new DefaultThreadFactory(name, /* daemon= */ true);
  if (Epoll.isAvailable()) {
    return new EpollEventLoopGroup(1, threadFactory);
  } else {
    return Executors.newSingleThreadScheduledExecutor(threadFactory);
  }
}