netty: use getOrCreate() for new instances of ChannelLogger AttributeKey. (#7048)

This commit is contained in:
Nicholas Titcombe 2020-05-21 12:43:35 -07:00 committed by GitHub
parent 0d6546719a
commit 3601190143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -68,7 +68,20 @@ import javax.annotation.Nullable;
* 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;