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

Method initChannel

netty/src/main/java/io/grpc/netty/NettyServer.java:246–313  ·  view source on GitHub ↗
(Channel ch)

Source from the content-addressed store, hash-verified

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,
275 maxConnectionAgeGraceInNanos,
276 permitKeepAliveWithoutCalls,
277 permitKeepAliveTimeInNanos,
278 maxRstCount,
279 maxRstPeriodNanos,
280 eagAttributes,
281 metricRecorder);
282 ServerTransportListener transportListener;
283 // This is to order callbacks on the listener, not to guard access to channel.
284 synchronized (NettyServer.this) {
285 if (terminated) {
286 // Server already terminated.
287 ch.close();
288 return;
289 }
290 // `channel` shutdown can race with `ch` initialization, so this is only safe to increment
291 // inside the lock.
292 sharedResourceReferenceCounter.retain();
293 transportListener = listener.transportCreated(transport);
294 }
295
296 /* Releases the event loop if the channel is "done", possibly due to the channel closing. */
297 final class LoopReleaser implements ChannelFutureListener {
298 private boolean done;
299
300 @Override
301 public void operationComplete(ChannelFuture future) throws Exception {
302 if (!done) {
303 done = true;

Callers

nothing calls this directly

Calls 7

startMethod · 0.95
retainMethod · 0.80
createMethod · 0.65
closeMethod · 0.65
transportCreatedMethod · 0.65
newPromiseMethod · 0.45
addListenerMethod · 0.45

Tested by

no test coverage detected