Fixing benchmarks build on non-linux systems.

This commit is contained in:
nmittler 2015-05-14 16:36:01 -07:00
parent 8f537e3ec6
commit c4c6c145af
3 changed files with 38 additions and 19 deletions

View File

@ -32,16 +32,20 @@ configurations {
} }
dependencies { dependencies {
compile project(':grpc-core'), List deps = [project(':grpc-core'),
project(':grpc-netty'), project(':grpc-netty'),
project(':grpc-okhttp'), project(':grpc-okhttp'),
project(':grpc-stub'), project(':grpc-stub'),
project(':grpc-integration-testing'), project(':grpc-integration-testing'),
libraries.junit, libraries.junit,
libraries.mockito, libraries.mockito,
libraries.hdrhistogram, libraries.hdrhistogram]
libraries.netty_tcnative, if (osdetector.os == "linux") {
libraries.netty_transport_native_epoll // These are only available on linux.
deps += [libraries.netty_tcnative, libraries.netty_transport_native_epoll]
}
compile deps
alpnboot alpnboot_package_name alpnboot alpnboot_package_name
} }

View File

@ -72,8 +72,6 @@ import io.grpc.transport.netty.NegotiationType;
import io.grpc.transport.netty.NettyChannelBuilder; import io.grpc.transport.netty.NettyChannelBuilder;
import io.grpc.transport.okhttp.OkHttpChannelBuilder; import io.grpc.transport.okhttp.OkHttpChannelBuilder;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
@ -201,8 +199,18 @@ public class AsyncClient {
final EventLoopGroup group; final EventLoopGroup group;
final Class<? extends io.netty.channel.Channel> channelType; final Class<? extends io.netty.channel.Channel> channelType;
if (config.nettyNativeTransport) { if (config.nettyNativeTransport) {
group = new EpollEventLoopGroup(); try {
channelType = EpollSocketChannel.class; // These classes are only available on linux.
Class<?> groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup");
@SuppressWarnings("unchecked")
Class<? extends io.netty.channel.Channel> channelClass =
(Class<? extends io.netty.channel.Channel>) Class.forName(
"io.netty.channel.epoll.EpollSocketChannel");
group = (EventLoopGroup) groupClass.newInstance();
channelType = channelClass;
} catch (Exception e) {
throw new RuntimeException(e);
}
} else { } else {
group = new NioEventLoopGroup(); group = new NioEventLoopGroup();
channelType = NioSocketChannel.class; channelType = NioSocketChannel.class;

View File

@ -50,8 +50,6 @@ import io.grpc.transport.netty.GrpcSslContexts;
import io.grpc.transport.netty.NettyServerBuilder; import io.grpc.transport.netty.NettyServerBuilder;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.SslContext; import io.netty.handler.ssl.SslContext;
@ -104,9 +102,18 @@ public class AsyncServer {
final EventLoopGroup worker; final EventLoopGroup worker;
final Class<? extends ServerChannel> channelType; final Class<? extends ServerChannel> channelType;
if (nettyNativeTransport) { if (nettyNativeTransport) {
boss = new EpollEventLoopGroup(); try {
worker = new EpollEventLoopGroup(); // These classes are only available on linux.
channelType = EpollServerSocketChannel.class; Class<?> groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup");
@SuppressWarnings("unchecked")
Class<? extends ServerChannel> channelClass = (Class<? extends ServerChannel>)
Class.forName("io.netty.channel.epoll.EpollServerSocketChannel");
boss = (EventLoopGroup) groupClass.newInstance();
worker = (EventLoopGroup) groupClass.newInstance();
channelType = channelClass;
} catch (Exception e) {
throw new RuntimeException(e);
}
} else { } else {
boss = new NioEventLoopGroup(); boss = new NioEventLoopGroup();
worker = new NioEventLoopGroup(); worker = new NioEventLoopGroup();