Java Code Examples for io.netty.channel.epoll.Epoll#isAvailable()

The following examples show how to use io.netty.channel.epoll.Epoll#isAvailable() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
Source File: TransportServerSupport.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
protected EventLoopGroup newIoEventGroup() {
    NamedThreadFactory threadFactory = new NamedThreadFactory(config.getIoThreadName());
    if (Epoll.isAvailable()) {
        return new EpollEventLoopGroup(config.getIoThread(), threadFactory);
    } else {
        return new NioEventLoopGroup(config.getIoThread(), threadFactory);
    }
}
 
Example 8
Source File: PCCDispatcherImpl.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
public PCCDispatcherImpl(final @NonNull MessageRegistry registry) {
    if (Epoll.isAvailable()) {
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.workerGroup = new NioEventLoopGroup();
    }
    this.factory = new PCEPHandlerFactory(registry);
}
 
Example 9
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 10
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 11
Source File: TransportTypeHolder.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example 12
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 13
Source File: BaseRedissonSessionManager.java    From redis-session-manager with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if native Epoll for netty is available
 * 
 * @return
 */
protected boolean isEpollSupported() {
    final boolean available = Epoll.isAvailable();
    if (available) {
        log.info("Using native epoll");
    }
    return available;
}
 
Example 14
Source File: AbstractNettyServer.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
public AbstractNettyServer(String preName,InetSocketAddress address) {
    super();
    this.enableEpoll = Epoll.isAvailable();
    this.serverAddress = address;
    this.name = NamespaceUtil.newIdName(preName,getClass());
    if(enableEpoll) {
        logger.info("enable epoll server = {}",this);
    }
}
 
Example 15
Source File: Connector.java    From serve with Apache License 2.0 4 votes vote down vote up
public Connector(int port) {
    this(port, useNativeIo && (Epoll.isAvailable() || KQueue.isAvailable()));
}
 
Example 16
Source File: UDPConfigBean.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public List<Stage.ConfigIssue> init(Stage.Context context) {
  List<Stage.ConfigIssue> issues = new ArrayList<>();
  addresses = new ArrayList<>();
  for (String candidatePort : ports) {
    try {
      int port = Integer.parseInt(candidatePort.trim());
      if (port > 0 && port < 65536) {
        if (port < 1024) {
          privilegedPortUsage = true; // only for error handling purposes
        }
        addresses.add(new InetSocketAddress(port));
      } else {
        issues.add(context.createConfigIssue(Groups.UDP.name(), "ports", Errors.UDP_KAFKA_ORIG_00, port));
      }
    } catch (NumberFormatException ex) {
      issues.add(context.createConfigIssue(Groups.UDP.name(),
          "ports",
          Errors.UDP_KAFKA_ORIG_00,
          candidatePort
      ));
    }
  }
  if (addresses.isEmpty()) {
    issues.add(context.createConfigIssue(Groups.UDP.name(), "ports", Errors.UDP_KAFKA_ORIG_03));
  }
  if (acceptThreads < 1 || acceptThreads > 32) {
    issues.add(context.createConfigIssue(Groups.ADVANCED.name(), "acceptThreads", Errors.UDP_KAFKA_ORIG_05));
  }
  if (concurrency < 1 || concurrency > 2048) {
    issues.add(context.createConfigIssue(Groups.UDP.name(), "concurrency", Errors.UDP_KAFKA_ORIG_04));
  }

  if (enableEpoll && !Epoll.isAvailable()) {
    issues.add(context.createConfigIssue(Groups.UDP.name(), "enableEpoll", Errors.UDP_KAFKA_ORIG_06));
  }

  // Force threads to 1 if epoll not enabled
  if (!enableEpoll) {
    acceptThreads = 1;
  }
  return issues;
}
 
Example 17
Source File: Netty.java    From grpc-proxy with Apache License 2.0 4 votes vote down vote up
public static EventLoopGroup newBossEventLoopGroup() {
  if (Epoll.isAvailable()) {
    return new EpollEventLoopGroup();
  }
  return new NioEventLoopGroup();
}
 
Example 18
Source File: NettyRemotingServer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
private boolean useEpoll() {
    return RemotingUtil.isLinuxPlatform()
        && nettyServerConfig.isUseEpollNativeSelector()
        && Epoll.isAvailable();
}
 
Example 19
Source File: NettyBootstrapServer.java    From InChat with Apache License 2.0 4 votes vote down vote up
private boolean useEpoll() {
    return RemotingUtil.isLinuxPlatform()
            && Epoll.isAvailable();
}
 
Example 20
Source File: TCPServerSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected List<ConfigIssue> init() {
  List<ConfigIssue> issues = new ArrayList<>();

  config.dataFormatConfig.stringBuilderPoolSize = config.numThreads;

  if (config.enableEpoll && !Epoll.isAvailable()) {
    issues.add(getContext().createConfigIssue(Groups.TCP.name(), CONF_PREFIX + "enableEpoll", Errors.TCP_05));
  }
  final String portsField = "ports";
  if (config.ports.isEmpty()) {
    issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_02));
  } else {
    for (String candidatePort : config.ports) {
      try {
        int port = Integer.parseInt(candidatePort.trim());
        if (port > 0 && port < 65536) {
          if (port < 1024) {
            privilegedPortUsage = true; // only for error handling purposes
          }
          addresses.add(new InetSocketAddress(port));
        } else {
          issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_03, port));
        }
      } catch (NumberFormatException ex) {
        issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_03, candidatePort));
      }
    }
  }

  if (issues.isEmpty()) {
    if (addresses.isEmpty()) {
      issues.add(getContext().createConfigIssue(Groups.TCP.name(), portsField, Errors.TCP_09));
    } else {
      if (config.tlsConfigBean.isEnabled()) {
        boolean tlsValid = config.tlsConfigBean.init(
            getContext(),
            Groups.TLS.name(),
            CONF_PREFIX + "tlsConfigBean.",
            issues
        );
        if (!tlsValid) {
          return issues;
        }
      }

      final boolean elValid = validateEls(issues);
      if (!elValid) {
        return issues;
      }

      validateTcpConfigs(issues);
      if (issues.size() > 0) {
        return issues;
      }

      if (config.tcpMode == TCPMode.FLUME_AVRO_IPC) {
        config.dataFormatConfig.init(
            getContext(),
            config.dataFormat,
            Groups.TCP.name(),
            CONF_PREFIX + "dataFormatConfig",
            config.maxMessageSize,
            issues
        );
        parserFactory = config.dataFormatConfig.getParserFactory();

        final int avroIpcPort = Integer.parseInt(config.ports.get(0));
        final SpecificResponder avroIpcResponder = new SpecificResponder(
            AvroSourceProtocol.class,
            new SDCFlumeAvroIpcProtocolHandler(getContext(), parserFactory, pipelineIdsToFail::put)
        );

        // this uses Netty 3.x code to help avoid rewriting a lot in our own stage lib
        // Netty 3.x and 4.x (which we use for the other modes) can coexist on the same classpath, so should be OK
        avroIpcServer = new NettyServer(
            avroIpcResponder,
            new InetSocketAddress(config.bindAddress, avroIpcPort)
        );

        avroIpcServer.start();
      } else {
        createAndStartTCPServer(issues, portsField);
      }
    }
  }
  return issues;
}