Skip to content

Commit

Permalink
netty: use getOrCreate() for new instances of ChannelLogger Attribute…
Browse files Browse the repository at this point in the history
…Key. (grpc#7048)
  • Loading branch information
Nexproc authored and creamsoup committed May 21, 2020
1 parent 0865c74 commit 21a2736
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion netty/src/main/java/io/grpc/netty/NettyClientTransport.java
Expand Up @@ -68,7 +68,20 @@
* A Netty-based {@link ConnectionClientTransport} implementation.
*/
class NettyClientTransport implements ConnectionClientTransport {
static final AttributeKey<ChannelLogger> LOGGER_KEY = AttributeKey.newInstance("channelLogger");

/**
* Get the existing {@link ChannelLogger} key in case a separate, isolated class loader has
* already created {@link LOGGER_KEY}.
*/
private static final AttributeKey<ChannelLogger> getOrCreateChannelLogger() {
AttributeKey<ChannelLogger> key = AttributeKey.valueOf("channelLogger");
if (key == null) {
key = AttributeKey.newInstance("channelLogger");
}
return key;
}

static final AttributeKey<ChannelLogger> LOGGER_KEY = getOrCreateChannelLogger();

private final InternalLogId logId;
private final Map<ChannelOption<?>, ?> channelOptions;
Expand Down

0 comments on commit 21a2736

Please sign in to comment.