MCPcopy Create free account
hub / github.com/grpc/grpc-java / Utils

Class Utils

netty/src/main/java/io/grpc/netty/Utils.java:78–604  ·  view source on GitHub ↗

Common utility methods.

Source from the content-addressed store, hash-verified

76 * Common utility methods.
77 */
78class Utils {
79 private static final Logger logger = Logger.getLogger(Utils.class.getName());
80
81 public static final AsciiString STATUS_OK = AsciiString.of("200");
82 public static final AsciiString HTTP_METHOD = AsciiString.of(GrpcUtil.HTTP_METHOD);
83 public static final AsciiString HTTP_GET_METHOD = AsciiString.of("GET");
84 public static final AsciiString HTTPS = AsciiString.of("https");
85 public static final AsciiString HTTP = AsciiString.of("http");
86 public static final AsciiString CONTENT_TYPE_HEADER = AsciiString.of(CONTENT_TYPE_KEY.name());
87 public static final AsciiString CONTENT_TYPE_GRPC = AsciiString.of(GrpcUtil.CONTENT_TYPE_GRPC);
88 public static final AsciiString TE_HEADER = AsciiString.of(GrpcUtil.TE_HEADER.name());
89 public static final AsciiString TE_TRAILERS = AsciiString.of(GrpcUtil.TE_TRAILERS);
90 public static final AsciiString USER_AGENT = AsciiString.of(GrpcUtil.USER_AGENT_KEY.name());
91 public static final Resource<EventLoopGroup> NIO_BOSS_EVENT_LOOP_GROUP
92 = new DefaultEventLoopGroupResource(1, "grpc-nio-boss-ELG", EventLoopGroupType.NIO);
93 public static final Resource<EventLoopGroup> NIO_WORKER_EVENT_LOOP_GROUP
94 = new DefaultEventLoopGroupResource(0, "grpc-nio-worker-ELG", EventLoopGroupType.NIO);
95 private static final int HEADER_ENTRY_OVERHEAD = 32;
96 private static final byte[] binaryHeaderSuffixBytes =
97 Metadata.BINARY_HEADER_SUFFIX.getBytes(US_ASCII);
98 public static final Resource<EventLoopGroup> DEFAULT_BOSS_EVENT_LOOP_GROUP;
99 public static final Resource<EventLoopGroup> DEFAULT_WORKER_EVENT_LOOP_GROUP;
100
101 // This class is initialized on first use, thus provides delayed allocator creation.
102 private static final class ByteBufAllocatorPreferDirectHolder {
103 private static final ByteBufAllocator allocator = createByteBufAllocator(true);
104 }
105
106 // This class is initialized on first use, thus provides delayed allocator creation.
107 private static final class ByteBufAllocatorPreferHeapHolder {
108 private static final ByteBufAllocator allocator = createByteBufAllocator(false);
109 }
110
111 public static final ChannelFactory<? extends ServerChannel> DEFAULT_SERVER_CHANNEL_FACTORY;
112 public static final Class<? extends Channel> DEFAULT_CLIENT_CHANNEL_TYPE;
113 public static final Class<? extends Channel> EPOLL_DOMAIN_CLIENT_CHANNEL_TYPE;
114
115 @Nullable
116 private static final Constructor<? extends EventLoopGroup> EPOLL_EVENT_LOOP_GROUP_CONSTRUCTOR;
117
118 static {
119 // Decide default channel types and EventLoopGroup based on Epoll availability
120 if (isEpollAvailable()) {
121 DEFAULT_CLIENT_CHANNEL_TYPE = epollChannelType();
122 EPOLL_DOMAIN_CLIENT_CHANNEL_TYPE = epollDomainSocketChannelType();
123 DEFAULT_SERVER_CHANNEL_FACTORY = new ReflectiveChannelFactory<>(epollServerChannelType());
124 EPOLL_EVENT_LOOP_GROUP_CONSTRUCTOR = epollEventLoopGroupConstructor();
125 DEFAULT_BOSS_EVENT_LOOP_GROUP = new DefaultEventLoopGroupResource(
126 1, "grpc-default-boss-ELG", EventLoopGroupType.EPOLL);
127 DEFAULT_WORKER_EVENT_LOOP_GROUP = new DefaultEventLoopGroupResource(
128 0, "grpc-default-worker-ELG", EventLoopGroupType.EPOLL);
129 } else {
130 logger.log(Level.FINE, "Epoll is not available, using Nio.", getEpollUnavailabilityCause());
131 DEFAULT_SERVER_CHANNEL_FACTORY = nioServerChannelFactory();
132 DEFAULT_CLIENT_CHANNEL_TYPE = NioSocketChannel.class;
133 EPOLL_DOMAIN_CLIENT_CHANNEL_TYPE = null;
134 DEFAULT_BOSS_EVENT_LOOP_GROUP = NIO_BOSS_EVENT_LOOP_GROUP;
135 DEFAULT_WORKER_EVENT_LOOP_GROUP = NIO_WORKER_EVENT_LOOP_GROUP;

Callers

nothing calls this directly

Calls 12

isEpollAvailableMethod · 0.95
epollChannelTypeMethod · 0.95
getBytesMethod · 0.80
getNameMethod · 0.65
ofMethod · 0.45
nameMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected