netty: fix visibility issues with InternalNettySocketSupport (#4335)

Previous version is not actually extendable from other packages.
This commit is contained in:
zpencer 2018-04-13 14:10:28 -07:00 committed by GitHub
parent 03465a7f45
commit c50a57cd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 5 deletions

View File

@ -17,6 +17,8 @@
package io.grpc.netty; package io.grpc.netty;
import io.grpc.Internal; import io.grpc.Internal;
import io.grpc.internal.Channelz.TcpInfo;
import java.util.Map;
/** /**
* An internal accessor. Do not use. * An internal accessor. Do not use.
@ -24,7 +26,17 @@ import io.grpc.Internal;
@Internal @Internal
public final class InternalNettySocketSupport { public final class InternalNettySocketSupport {
public interface InternalHelper extends NettySocketSupport.Helper { } public interface InternalHelper extends NettySocketSupport.Helper {
@Override
InternalNativeSocketOptions getNativeSocketOptions(io.netty.channel.Channel ch);
}
public static final class InternalNativeSocketOptions
extends NettySocketSupport.NativeSocketOptions {
public InternalNativeSocketOptions(TcpInfo tcpInfo, Map<String, String> otherInfo) {
super(tcpInfo, otherInfo);
}
}
public static void setHelper(InternalHelper helper) { public static void setHelper(InternalHelper helper) {
NettySocketSupport.setHelper(helper); NettySocketSupport.setHelper(helper);

View File

@ -27,7 +27,7 @@ import javax.annotation.Nullable;
* An class for getting low level socket info. * An class for getting low level socket info.
*/ */
final class NettySocketSupport { final class NettySocketSupport {
private static volatile Helper INSTANCE = new NettySocketHelperImpl(); private static volatile Helper instance = new NettySocketHelperImpl();
interface Helper { interface Helper {
/** /**
@ -40,7 +40,7 @@ final class NettySocketSupport {
/** /**
* A TcpInfo and additional other info that will be turned into channelz socket options. * A TcpInfo and additional other info that will be turned into channelz socket options.
*/ */
public static final class NativeSocketOptions { public static class NativeSocketOptions {
@Nullable @Nullable
public final TcpInfo tcpInfo; public final TcpInfo tcpInfo;
public final ImmutableMap<String, String> otherInfo; public final ImmutableMap<String, String> otherInfo;
@ -56,11 +56,11 @@ final class NettySocketSupport {
} }
public static NativeSocketOptions getNativeSocketOptions(Channel ch) { public static NativeSocketOptions getNativeSocketOptions(Channel ch) {
return INSTANCE.getNativeSocketOptions(ch); return instance.getNativeSocketOptions(ch);
} }
static void setHelper(Helper helper) { static void setHelper(Helper helper) {
INSTANCE = Preconditions.checkNotNull(helper); instance = Preconditions.checkNotNull(helper);
} }
private static final class NettySocketHelperImpl implements Helper { private static final class NettySocketHelperImpl implements Helper {