4747import io .netty .channel .ChannelFuture ;
4848import io .netty .channel .ChannelFutureListener ;
4949import io .netty .channel .EventLoopGroup ;
50- import io .netty .channel .local .LocalAddress ;
51- import io .netty .channel .local .LocalChannel ;
5250import io .netty .channel .socket .nio .NioSocketChannel ;
5351import io .netty .handler .codec .AsciiString ;
5452import io .netty .handler .codec .http2 .DefaultHttp2Connection ;
@@ -85,6 +83,7 @@ class NettyClientTransport implements ClientTransport {
8583 private static final Logger log = Logger .getLogger (NettyClientTransport .class .getName ());
8684
8785 private final SocketAddress address ;
86+ private final Class <? extends Channel > channelType ;
8887 private final EventLoopGroup group ;
8988 private final Http2Negotiator .Negotiation negotiation ;
9089 private final NettyClientHandler handler ;
@@ -109,22 +108,23 @@ class NettyClientTransport implements ClientTransport {
109108 @ GuardedBy ("this" )
110109 private boolean terminated ;
111110
112- NettyClientTransport (SocketAddress address , NegotiationType negotiationType ,
113- EventLoopGroup group , SslContext sslContext ) {
111+ NettyClientTransport (SocketAddress address , Class <? extends Channel > channelType ,
112+ NegotiationType negotiationType , EventLoopGroup group , SslContext sslContext ) {
114113 Preconditions .checkNotNull (negotiationType , "negotiationType" );
115114 this .address = Preconditions .checkNotNull (address , "address" );
116115 this .group = Preconditions .checkNotNull (group , "group" );
116+ this .channelType = Preconditions .checkNotNull (channelType , "channelType" );
117117
118118 InetSocketAddress inetAddress = null ;
119119 if (address instanceof InetSocketAddress ) {
120120 inetAddress = (InetSocketAddress ) address ;
121121 authority = new AsciiString (inetAddress .getHostString () + ":" + inetAddress .getPort ());
122- } else if (address instanceof LocalAddress ) {
123- authority = new AsciiString (address .toString ());
124- Preconditions .checkArgument (negotiationType != NegotiationType .TLS ,
125- "TLS not supported for in-process transport" );
126122 } else {
127- throw new IllegalStateException ("Unknown socket address type " + address .toString ());
123+ Preconditions .checkState (negotiationType != NegotiationType .TLS ,
124+ "TLS not supported for non-internet socket types" );
125+ // Specialized address types are allowed to support custom Channel types so just assume their
126+ // toString() values are valid :authority values
127+ authority = new AsciiString (address .toString ());
128128 }
129129
130130 DefaultHttp2StreamRemovalPolicy streamRemovalPolicy = new DefaultHttp2StreamRemovalPolicy ();
@@ -201,10 +201,8 @@ public void start(Listener transportListener) {
201201 listener = Preconditions .checkNotNull (transportListener , "listener" );
202202 Bootstrap b = new Bootstrap ();
203203 b .group (group );
204- if (address instanceof LocalAddress ) {
205- b .channel (LocalChannel .class );
206- } else {
207- b .channel (NioSocketChannel .class );
204+ b .channel (channelType );
205+ if (NioSocketChannel .class .isAssignableFrom (channelType )) {
208206 b .option (SO_KEEPALIVE , true );
209207 }
210208 b .handler (negotiation .initializer ());
0 commit comments