1 /* 2 * Copyright 2016 The gRPC Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package io.grpc.benchmarks; 18 19 import java.net.SocketAddress; 20 21 /** 22 * All of the supported transports. 23 */ 24 public enum Transport { 25 NETTY_NIO(true, "The Netty Java NIO transport. Using this with TLS requires " 26 + "that the Java bootclasspath be configured with Jetty ALPN boot.", 27 SocketAddressValidator.INET), 28 NETTY_EPOLL(true, "The Netty native EPOLL transport. Using this with TLS requires that " 29 + "OpenSSL be installed and configured as described in " 30 + "http://netty.io/wiki/forked-tomcat-native.html. Only supported on Linux.", 31 SocketAddressValidator.INET), 32 NETTY_UNIX_DOMAIN_SOCKET(false, "The Netty Unix Domain Socket transport. This currently " 33 + "does not support TLS.", SocketAddressValidator.UDS), 34 OK_HTTP(true, "The OkHttp transport.", SocketAddressValidator.INET); 35 36 public final boolean tlsSupported; 37 final String description; 38 final SocketAddressValidator socketAddressValidator; 39 Transport(boolean tlsSupported, String description, SocketAddressValidator socketAddressValidator)40 Transport(boolean tlsSupported, String description, 41 SocketAddressValidator socketAddressValidator) { 42 this.tlsSupported = tlsSupported; 43 this.description = description; 44 this.socketAddressValidator = socketAddressValidator; 45 } 46 47 /** 48 * Validates the given address for this transport. 49 * 50 * @throws IllegalArgumentException if the given address is invalid for this transport. 51 */ validateSocketAddress(SocketAddress address)52 public void validateSocketAddress(SocketAddress address) { 53 if (!socketAddressValidator.isValidSocketAddress(address)) { 54 throw new IllegalArgumentException( 55 "Invalid address " + address + " for transport " + this); 56 } 57 } 58 59 /** 60 * Describe the {@link Transport}. 61 */ getDescriptionString()62 public static String getDescriptionString() { 63 StringBuilder builder = new StringBuilder("Select the transport to use. Options:\n"); 64 boolean first = true; 65 for (Transport transport : Transport.values()) { 66 if (!first) { 67 builder.append("\n"); 68 } 69 builder.append(transport.name().toLowerCase()); 70 builder.append(": "); 71 builder.append(transport.description); 72 first = false; 73 } 74 return builder.toString(); 75 } 76 } 77