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

Method start

netty/src/main/java/io/grpc/netty/NettyServer.java:217–361  ·  view source on GitHub ↗
(ServerListener serverListener)

Source from the content-addressed store, hash-verified

215 }
216
217 @Override
218 public void start(ServerListener serverListener) throws IOException {
219 listener = checkNotNull(serverListener, "serverListener");
220
221 final ServerBootstrap b = new ServerBootstrap();
222 b.option(ALLOCATOR, Utils.getByteBufAllocator(forceHeapBuffer));
223 b.childOption(ALLOCATOR, Utils.getByteBufAllocator(forceHeapBuffer));
224 b.group(bossExecutor, workerGroup);
225 b.channelFactory(channelFactory);
226 // For non-socket based channel, the option will be ignored.
227 b.childOption(SO_KEEPALIVE, true);
228
229 if (channelOptions != null) {
230 for (Map.Entry<ChannelOption<?>, ?> entry : channelOptions.entrySet()) {
231 @SuppressWarnings("unchecked")
232 ChannelOption<Object> key = (ChannelOption<Object>) entry.getKey();
233 b.option(key, entry.getValue());
234 }
235 }
236
237 if (childChannelOptions != null) {
238 for (Map.Entry<ChannelOption<?>, ?> entry : childChannelOptions.entrySet()) {
239 @SuppressWarnings("unchecked")
240 ChannelOption<Object> key = (ChannelOption<Object>) entry.getKey();
241 b.childOption(key, entry.getValue());
242 }
243 }
244
245 b.childHandler(new ChannelInitializer<Channel>() {
246 @Override
247 public void initChannel(Channel ch) {
248
249 ChannelPromise channelDone = ch.newPromise();
250
251 long maxConnectionAgeInNanos = NettyServer.this.maxConnectionAgeInNanos;
252 if (maxConnectionAgeInNanos != MAX_CONNECTION_AGE_NANOS_DISABLED) {
253 // apply a random jitter of +/-10% to max connection age
254 maxConnectionAgeInNanos =
255 (long) ((.9D + Math.random() * .2D) * maxConnectionAgeInNanos);
256 }
257
258 NettyServerTransport transport =
259 new NettyServerTransport(
260 ch,
261 channelDone,
262 protocolNegotiator,
263 streamTracerFactories,
264 transportTracerFactory.create(),
265 maxStreamsPerConnection,
266 autoFlowControl,
267 flowControlWindow,
268 maxMessageSize,
269 maxHeaderListSize,
270 softLimitHeaderListSize,
271 keepAliveTimeInNanos,
272 keepAliveTimeoutInNanos,
273 maxConnectionIdleInNanos,
274 maxConnectionAgeInNanos,

Callers 6

startStopMethod · 0.95
multiPortStartStopGetMethod · 0.95
multiPortConnectionsMethod · 0.95
channelzListenSocketMethod · 0.95
verifyServerNotStartMethod · 0.95

Calls 11

getByteBufAllocatorMethod · 0.95
checkNotNullMethod · 0.80
addListenSocketMethod · 0.80
closeMethod · 0.65
addMethod · 0.65
channelFactoryMethod · 0.45
getKeyMethod · 0.45
getValueMethod · 0.45
submitMethod · 0.45
channelMethod · 0.45
addListenerMethod · 0.45

Tested by 6

startStopMethod · 0.76
multiPortStartStopGetMethod · 0.76
multiPortConnectionsMethod · 0.76
channelzListenSocketMethod · 0.76
verifyServerNotStartMethod · 0.76