io.netty.channel.epoll.Epoll#isAvailable ( )源码实例Demo

下面列出了io.netty.channel.epoll.Epoll#isAvailable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bazel   文件: GoogleAuthUtils.java
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");
}
 
源代码2 项目: arcusplatform   文件: GatewayNetty.java
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();
   }
}
 
源代码3 项目: kyoko   文件: VoiceWebsocket.java
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;
}
 
源代码4 项目: credhub   文件: KMSEncryptionProvider.java
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.");
  }

}
 
源代码5 项目: pulsar   文件: EventLoopUtil.java
/**
 * @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);
    }
}
 
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);
    }
}
 
/**
 * 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;
}
 
源代码8 项目: bgpcep   文件: BGPDispatcherImpl.java
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);
}
 
源代码9 项目: blynk-server   文件: TransportTypeHolder.java
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;
    }
}
 
源代码10 项目: armeria   文件: Flags.java
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;
}
 
源代码11 项目: bazel-buildfarm   文件: HttpBlobStore.java
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");
  }
}
 
源代码12 项目: bgpcep   文件: PCCDispatcherImpl.java
public PCCDispatcherImpl(final @NonNull MessageRegistry registry) {
    if (Epoll.isAvailable()) {
        this.workerGroup = new EpollEventLoopGroup();
    } else {
        this.workerGroup = new NioEventLoopGroup();
    }
    this.factory = new PCEPHandlerFactory(registry);
}
 
源代码13 项目: joyqueue   文件: TransportServerSupport.java
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);
    }
}
 
源代码14 项目: qpid-jms   文件: EpollSupport.java
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;
    }
}
 
源代码15 项目: datacollector   文件: TCPServerSource.java
@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;
}
 
源代码16 项目: InChat   文件: NettyBootstrapServer.java
private boolean useEpoll() {
    return RemotingUtil.isLinuxPlatform()
            && Epoll.isAvailable();
}
 
源代码17 项目: grpc-proxy   文件: Netty.java
public static EventLoopGroup newBossEventLoopGroup() {
  if (Epoll.isAvailable()) {
    return new EpollEventLoopGroup();
  }
  return new NioEventLoopGroup();
}
 
源代码18 项目: serve   文件: Connector.java
public Connector(int port) {
    this(port, useNativeIo && (Epoll.isAvailable() || KQueue.isAvailable()));
}
 
源代码19 项目: datacollector   文件: UDPConfigBean.java
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;
}
 
private boolean useEpoll() {
    return RemotingUtil.isLinuxPlatform()
        && nettyServerConfig.isUseEpollNativeSelector()
        && Epoll.isAvailable();
}
 
 方法所在类
 同类方法