类io.netty.channel.epoll.EpollDomainSocketChannel源码实例Demo

下面列出了怎么用io.netty.channel.epoll.EpollDomainSocketChannel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: reactor-netty   文件: DefaultLoopEpoll.java
@Override
@SuppressWarnings("unchecked")
public <CHANNEL extends Channel> CHANNEL getChannel(Class<CHANNEL> channelClass) {
	if (channelClass.equals(SocketChannel.class)) {
		return (CHANNEL) new EpollSocketChannel();
	}
	if (channelClass.equals(ServerSocketChannel.class)) {
		return (CHANNEL) new EpollServerSocketChannel();
	}
	if (channelClass.equals(DatagramChannel.class)) {
		return (CHANNEL) new EpollDatagramChannel();
	}
	if (channelClass.equals(DomainSocketChannel.class)) {
		return (CHANNEL) new EpollDomainSocketChannel();
	}
	if (channelClass.equals(ServerDomainSocketChannel.class)) {
		return (CHANNEL) new EpollServerDomainSocketChannel();
	}
	throw new IllegalArgumentException("Unsupported channel type: " + channelClass.getSimpleName());
}
 
源代码2 项目: 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.");
  }

}
 
源代码3 项目: 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");
}
 
源代码4 项目: selenium   文件: NettyDomainSocketClient.java
public NettyDomainSocketClient(ClientConfig config) {
  super(config);
  URI uri = config.baseUri();
  Require.argument("URI scheme", uri.getScheme()).equalTo("unix");

  if (Epoll.isAvailable()) {
    this.eventLoopGroup = new EpollEventLoopGroup();
    this.channelClazz = EpollDomainSocketChannel.class;
  } else if (KQueue.isAvailable()) {
    this.eventLoopGroup = new KQueueEventLoopGroup();
    this.channelClazz = KQueueDomainSocketChannel.class;
  } else {
    throw new IllegalStateException("No native library for unix domain sockets is available");
  }

  this.path = uri.getPath();
}
 
源代码5 项目: grpc-nebula-java   文件: Utils.java
private static NettyChannelBuilder newNettyClientChannel(Transport transport,
    SocketAddress address, boolean tls, boolean testca, int flowControlWindow)
    throws IOException {
  NettyChannelBuilder builder =
      NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow);
  if (!tls) {
    builder.usePlaintext();
  } else if (testca) {
    File cert = TestUtils.loadCert("ca.pem");
    builder.sslContext(GrpcSslContexts.forClient().trustManager(cert).build());
  }

  DefaultThreadFactory tf = new DefaultThreadFactory("client-elg-", true /*daemon */);
  switch (transport) {
    case NETTY_NIO:
      builder
          .eventLoopGroup(new NioEventLoopGroup(0, tf))
          .channelType(NioSocketChannel.class);
      break;

    case NETTY_EPOLL:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollSocketChannel.class);
      break;

    case NETTY_UNIX_DOMAIN_SOCKET:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollDomainSocketChannel.class);
      break;

    default:
      // Should never get here.
      throw new IllegalArgumentException("Unsupported transport: " + transport);
  }
  return builder;
}
 
源代码6 项目: serve   文件: Connector.java
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;
}
 
源代码7 项目: servicetalk   文件: BuilderUtils.java
/**
 * Returns the correct {@link Class} to use with the given {@link EventLoopGroup}.
 *
 * @param group        the {@link EventLoopGroup} for which the class is needed
 * @param addressClass The class of the address that to connect to.
 * @return the class that should be used for bootstrapping
 */
public static Class<? extends Channel> socketChannel(EventLoopGroup group,
                                                     Class<? extends SocketAddress> addressClass) {
    if (useEpoll(group)) {
        return DomainSocketAddress.class.isAssignableFrom(addressClass) ? EpollDomainSocketChannel.class :
                EpollSocketChannel.class;
    } else if (useKQueue(group)) {
        return DomainSocketAddress.class.isAssignableFrom(addressClass) ? KQueueDomainSocketChannel.class :
                KQueueSocketChannel.class;
    } else {
        return NioSocketChannel.class;
    }
}
 
源代码8 项目: multi-model-server   文件: Connector.java
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;
}
 
源代码9 项目: 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");
  }
}
 
源代码10 项目: Jupiter   文件: SocketChannelProvider.java
@SuppressWarnings("unchecked")
@Override
public T newChannel() {
    switch (channelType) {
        case ACCEPTOR:
            switch (socketType) {
                case JAVA_NIO:
                    return (T) new NioServerSocketChannel();
                case NATIVE_EPOLL:
                    return (T) new EpollServerSocketChannel();
                case NATIVE_KQUEUE:
                    return (T) new KQueueServerSocketChannel();
                case NATIVE_EPOLL_DOMAIN:
                    return (T) new EpollServerDomainSocketChannel();
                case NATIVE_KQUEUE_DOMAIN:
                    return (T) new KQueueServerDomainSocketChannel();
                default:
                    throw new IllegalStateException("Invalid socket type: " + socketType);
            }
        case CONNECTOR:
            switch (socketType) {
                case JAVA_NIO:
                    return (T) new NioSocketChannel();
                case NATIVE_EPOLL:
                    return (T) new EpollSocketChannel();
                case NATIVE_KQUEUE:
                    return (T) new KQueueSocketChannel();
                case NATIVE_EPOLL_DOMAIN:
                    return (T) new EpollDomainSocketChannel();
                case NATIVE_KQUEUE_DOMAIN:
                    return (T) new KQueueDomainSocketChannel();
                default:
                    throw new IllegalStateException("Invalid socket type: " + socketType);
            }
        default:
            throw new IllegalStateException("Invalid channel type: " + channelType);
    }
}
 
源代码11 项目: bazel   文件: HttpCacheClient.java
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");
  }
}
 
源代码12 项目: docker-java   文件: NettyDockerCmdExecFactory.java
public EventLoopGroup epollGroup() {
    EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));

    ChannelFactory<EpollDomainSocketChannel> factory = () -> configure(new EpollDomainSocketChannel());

    bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer<UnixChannel>() {
        @Override
        protected void initChannel(final UnixChannel channel) throws Exception {
            channel.pipeline().addLast(new HttpClientCodec());
            channel.pipeline().addLast(new HttpContentDecompressor());
        }
    });
    return epollEventLoopGroup;
}
 
源代码13 项目: grpc-java   文件: Utils.java
private static NettyChannelBuilder newNettyClientChannel(Transport transport,
    SocketAddress address, boolean tls, boolean testca, int flowControlWindow)
    throws IOException {
  NettyChannelBuilder builder =
      NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow);
  if (!tls) {
    builder.usePlaintext();
  } else if (testca) {
    File cert = TestUtils.loadCert("ca.pem");
    builder.sslContext(GrpcSslContexts.forClient().trustManager(cert).build());
  }

  DefaultThreadFactory tf = new DefaultThreadFactory("client-elg-", true /*daemon */);
  switch (transport) {
    case NETTY_NIO:
      builder
          .eventLoopGroup(new NioEventLoopGroup(0, tf))
          .channelType(NioSocketChannel.class);
      break;

    case NETTY_EPOLL:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollSocketChannel.class);
      break;

    case NETTY_UNIX_DOMAIN_SOCKET:
      // These classes only work on Linux.
      builder
          .eventLoopGroup(new EpollEventLoopGroup(0, tf))
          .channelType(EpollDomainSocketChannel.class);
      break;

    default:
      // Should never get here.
      throw new IllegalArgumentException("Unsupported transport: " + transport);
  }
  return builder;
}
 
 类所在包
 同包方法