public EventLoopGroup epollGroup() { EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix)); ChannelFactory<EpollDomainSocketChannel> factory = new ChannelFactory<EpollDomainSocketChannel>() { @Override public EpollDomainSocketChannel newChannel() { return 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()); } }); return epollEventLoopGroup; }
@Override public ManagedChannel forDescriptor(ApiServiceDescriptor apiServiceDescriptor) { SocketAddress address = SocketAddressFactory.createFrom(apiServiceDescriptor.getUrl()); return NettyChannelBuilder.forAddress(address) .channelType(address instanceof DomainSocketAddress ? EpollDomainSocketChannel.class : EpollSocketChannel.class) .eventLoopGroup(new EpollEventLoopGroup()) .usePlaintext(true) // Set the message size to max value here. The actual size is governed by the // buffer size in the layers above. .maxInboundMessageSize(Integer.MAX_VALUE) .build(); }
@Override public Class<? extends Channel> domainSocketChannelClass() { checkForEpollLibrary(); return EpollDomainSocketChannel.class; }
private static NettyChannelBuilder newNettyClientChannel(Transport transport, SocketAddress address, boolean tls, boolean testca, int flowControlWindow, boolean useDefaultCiphers) throws IOException { NettyChannelBuilder builder = NettyChannelBuilder.forAddress(address).flowControlWindow(flowControlWindow); if (tls) { builder.negotiationType(NegotiationType.TLS); SslContext sslContext = null; if (testca) { File cert = TestUtils.loadCert("ca.pem"); SslContextBuilder sslContextBuilder = GrpcSslContexts.forClient().trustManager(cert); if (transport == Transport.NETTY_NIO) { sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.JDK); } else { // Native transport with OpenSSL sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.OPENSSL); } if (useDefaultCiphers) { sslContextBuilder.ciphers(null); } sslContext = sslContextBuilder.build(); } builder.sslContext(sslContext); } else { builder.negotiationType(NegotiationType.PLAINTEXT); } 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; }