1616
1717package io .grpc .netty ;
1818
19- import static com .google .common .base .Preconditions .checkNotNull ;
2019import static com .google .common .base .Preconditions .checkState ;
2120
2221import com .google .common .annotations .VisibleForTesting ;
2322import com .google .common .base .Optional ;
23+ import com .google .common .base .Preconditions ;
2424import com .google .errorprone .annotations .ForOverride ;
2525import io .grpc .Attributes ;
2626import io .grpc .CallCredentials ;
4646import io .grpc .internal .GrpcUtil ;
4747import io .grpc .internal .NoopSslSession ;
4848import io .grpc .internal .ObjectPool ;
49- import io .netty .channel .Channel ;
5049import io .netty .channel .ChannelDuplexHandler ;
5150import io .netty .channel .ChannelFutureListener ;
5251import io .netty .channel .ChannelHandler ;
6160import io .netty .handler .codec .http2 .Http2ClientUpgradeCodec ;
6261import io .netty .handler .proxy .HttpProxyHandler ;
6362import io .netty .handler .proxy .ProxyConnectionEvent ;
64- import io .netty .handler .ssl .ClientAuth ;
6563import io .netty .handler .ssl .OpenSsl ;
6664import io .netty .handler .ssl .OpenSslEngine ;
6765import io .netty .handler .ssl .SslContext ;
@@ -225,15 +223,15 @@ public static FromServerCredentialsResult from(ServerCredentials creds) {
225223 } // else use system default
226224 switch (tlsCreds .getClientAuth ()) {
227225 case OPTIONAL :
228- builder .clientAuth (ClientAuth .OPTIONAL );
226+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .OPTIONAL );
229227 break ;
230228
231229 case REQUIRE :
232- builder .clientAuth (ClientAuth .REQUIRE );
230+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .REQUIRE );
233231 break ;
234232
235233 case NONE :
236- builder .clientAuth (ClientAuth .NONE );
234+ builder .clientAuth (io . netty . handler . ssl . ClientAuth .NONE );
237235 break ;
238236
239237 default :
@@ -289,17 +287,17 @@ private FromChannelCredentialsResult(ProtocolNegotiator.ClientFactory negotiator
289287
290288 public static FromChannelCredentialsResult error (String error ) {
291289 return new FromChannelCredentialsResult (
292- null , null , checkNotNull (error , "error" ));
290+ null , null , Preconditions . checkNotNull (error , "error" ));
293291 }
294292
295293 public static FromChannelCredentialsResult negotiator (
296294 ProtocolNegotiator .ClientFactory factory ) {
297295 return new FromChannelCredentialsResult (
298- checkNotNull (factory , "factory" ), null , null );
296+ Preconditions . checkNotNull (factory , "factory" ), null , null );
299297 }
300298
301299 public FromChannelCredentialsResult withCallCredentials (CallCredentials callCreds ) {
302- checkNotNull (callCreds , "callCreds" );
300+ Preconditions . checkNotNull (callCreds , "callCreds" );
303301 if (error != null ) {
304302 return this ;
305303 }
@@ -320,11 +318,11 @@ private FromServerCredentialsResult(ProtocolNegotiator.ServerFactory negotiator,
320318 }
321319
322320 public static FromServerCredentialsResult error (String error ) {
323- return new FromServerCredentialsResult (null , checkNotNull (error , "error" ));
321+ return new FromServerCredentialsResult (null , Preconditions . checkNotNull (error , "error" ));
324322 }
325323
326324 public static FromServerCredentialsResult negotiator (ProtocolNegotiator .ServerFactory factory ) {
327- return new FromServerCredentialsResult (checkNotNull (factory , "factory" ), null );
325+ return new FromServerCredentialsResult (Preconditions . checkNotNull (factory , "factory" ), null );
328326 }
329327 }
330328
@@ -339,7 +337,7 @@ private static final class FixedProtocolNegotiatorServerFactory
339337
340338 public FixedProtocolNegotiatorServerFactory (ProtocolNegotiator protocolNegotiator ) {
341339 this .protocolNegotiator =
342- checkNotNull (protocolNegotiator , "protocolNegotiator" );
340+ Preconditions . checkNotNull (protocolNegotiator , "protocolNegotiator" );
343341 }
344342
345343 @ Override
@@ -381,7 +379,7 @@ static final class TlsProtocolNegotiatorServerFactory
381379 private final SslContext sslContext ;
382380
383381 public TlsProtocolNegotiatorServerFactory (SslContext sslContext ) {
384- this .sslContext = checkNotNull (sslContext , "sslContext" );
382+ this .sslContext = Preconditions . checkNotNull (sslContext , "sslContext" );
385383 }
386384
387385 @ Override
@@ -396,7 +394,7 @@ public ProtocolNegotiator newNegotiator(ObjectPool<? extends Executor> offloadEx
396394 */
397395 public static ProtocolNegotiator serverTls (final SslContext sslContext ,
398396 final ObjectPool <? extends Executor > executorPool ) {
399- checkNotNull (sslContext , "sslContext" );
397+ Preconditions . checkNotNull (sslContext , "sslContext" );
400398 final Executor executor ;
401399 if (executorPool != null ) {
402400 // The handlers here can out-live the {@link ProtocolNegotiator}.
@@ -446,8 +444,8 @@ static final class ServerTlsHandler extends ChannelInboundHandlerAdapter {
446444 ServerTlsHandler (ChannelHandler next ,
447445 SslContext sslContext ,
448446 final ObjectPool <? extends Executor > executorPool ) {
449- this .sslContext = checkNotNull (sslContext , "sslContext" );
450- this .next = checkNotNull (next , "next" );
447+ this .sslContext = Preconditions . checkNotNull (sslContext , "sslContext" );
448+ this .next = Preconditions . checkNotNull (next , "next" );
451449 if (executorPool != null ) {
452450 this .executor = executorPool .getObject ();
453451 }
@@ -504,8 +502,8 @@ private void fireProtocolNegotiationEvent(ChannelHandlerContext ctx, SSLSession
504502 public static ProtocolNegotiator httpProxy (final SocketAddress proxyAddress ,
505503 final @ Nullable String proxyUsername , final @ Nullable String proxyPassword ,
506504 final ProtocolNegotiator negotiator ) {
507- checkNotNull (negotiator , "negotiator" );
508- checkNotNull (proxyAddress , "proxyAddress" );
505+ Preconditions . checkNotNull (negotiator , "negotiator" );
506+ Preconditions . checkNotNull (proxyAddress , "proxyAddress" );
509507 final AsciiString scheme = negotiator .scheme ();
510508 class ProxyNegotiator implements ProtocolNegotiator {
511509 @ Override
@@ -551,7 +549,7 @@ public ProxyProtocolNegotiationHandler(
551549 ChannelHandler next ,
552550 ChannelLogger negotiationLogger ) {
553551 super (next , negotiationLogger );
554- this .address = checkNotNull (address , "address" );
552+ this .address = Preconditions . checkNotNull (address , "address" );
555553 this .userName = userName ;
556554 this .password = password ;
557555 }
@@ -582,7 +580,7 @@ static final class ClientTlsProtocolNegotiator implements ProtocolNegotiator {
582580 public ClientTlsProtocolNegotiator (SslContext sslContext ,
583581 ObjectPool <? extends Executor > executorPool , Optional <Runnable > handshakeCompleteRunnable ,
584582 X509TrustManager x509ExtendedTrustManager ) {
585- this .sslContext = checkNotNull (sslContext , "sslContext" );
583+ this .sslContext = Preconditions . checkNotNull (sslContext , "sslContext" );
586584 this .executorPool = executorPool ;
587585 if (this .executorPool != null ) {
588586 this .executor = this .executorPool .getObject ();
@@ -630,7 +628,6 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
630628 private final SslContext sslContext ;
631629 private final String host ;
632630 private final int port ;
633- private final ClientTlsProtocolNegotiator clientTlsProtocolNegotiator ;
634631 private Executor executor ;
635632 private final Optional <Runnable > handshakeCompleteRunnable ;
636633 private final X509TrustManager x509ExtendedTrustManager ;
@@ -642,13 +639,12 @@ static final class ClientTlsHandler extends ProtocolNegotiationHandler {
642639 ClientTlsProtocolNegotiator clientTlsProtocolNegotiator ,
643640 X509TrustManager x509ExtendedTrustManager ) {
644641 super (next , negotiationLogger );
645- this .sslContext = checkNotNull (sslContext , "sslContext" );
642+ this .sslContext = Preconditions . checkNotNull (sslContext , "sslContext" );
646643 HostPort hostPort = parseAuthority (authority );
647644 this .host = hostPort .host ;
648645 this .port = hostPort .port ;
649646 this .executor = executor ;
650647 this .handshakeCompleteRunnable = handshakeCompleteRunnable ;
651- this .clientTlsProtocolNegotiator = clientTlsProtocolNegotiator ;
652648 this .x509ExtendedTrustManager = x509ExtendedTrustManager ;
653649 }
654650
@@ -725,7 +721,7 @@ private void propagateTlsComplete(ChannelHandlerContext ctx, SSLSession session)
725721
726722 @ VisibleForTesting
727723 static HostPort parseAuthority (String authority ) {
728- URI uri = GrpcUtil .authorityToUri (checkNotNull (authority , "authority" ));
724+ URI uri = GrpcUtil .authorityToUri (Preconditions . checkNotNull (authority , "authority" ));
729725 String host ;
730726 int port ;
731727 if (uri .getHost () != null ) {
@@ -748,7 +744,7 @@ static HostPort parseAuthority(String authority) {
748744
749745 /**
750746 * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
751- * be negotiated, the {@code handler} is added and writes to the {@link Channel}
747+ * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel. Channel}
752748 * may happen immediately, even before the TLS Handshake is complete.
753749 * @param executorPool a dedicated {@link Executor} pool for time-consuming TLS tasks
754750 */
@@ -761,7 +757,7 @@ public static ProtocolNegotiator tls(SslContext sslContext,
761757
762758 /**
763759 * Returns a {@link ProtocolNegotiator} that ensures the pipeline is set up so that TLS will
764- * be negotiated, the {@code handler} is added and writes to the {@link Channel}
760+ * be negotiated, the {@code handler} is added and writes to the {@link io.netty.channel. Channel}
765761 * may happen immediately, even before the TLS Handshake is complete.
766762 */
767763 public static ProtocolNegotiator tls (SslContext sslContext ,
@@ -783,7 +779,7 @@ static final class TlsProtocolNegotiatorClientFactory
783779
784780 public TlsProtocolNegotiatorClientFactory (SslContext sslContext ,
785781 X509TrustManager x509ExtendedTrustManager ) {
786- this .sslContext = checkNotNull (sslContext , "sslContext" );
782+ this .sslContext = Preconditions . checkNotNull (sslContext , "sslContext" );
787783 this .x509ExtendedTrustManager = x509ExtendedTrustManager ;
788784 }
789785
@@ -862,8 +858,8 @@ static final class Http2UpgradeAndGrpcHandler extends ChannelInboundHandlerAdapt
862858 private ProtocolNegotiationEvent pne ;
863859
864860 Http2UpgradeAndGrpcHandler (String authority , GrpcHttp2ConnectionHandler next ) {
865- this .authority = checkNotNull (authority , "authority" );
866- this .next = checkNotNull (next , "next" );
861+ this .authority = Preconditions . checkNotNull (authority , "authority" );
862+ this .next = Preconditions . checkNotNull (next , "next" );
867863 this .negotiationLogger = next .getNegotiationLogger ();
868864 }
869865
@@ -907,9 +903,9 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
907903 }
908904
909905 /**
910- * Returns a {@link ChannelHandler} that ensures that the {@code handler} is added to the
911- * pipeline writes to the {@link Channel} may happen immediately, even before it
912- * is active.
906+ * Returns a {@link io.netty.channel. ChannelHandler} that ensures that the {@code handler} is
907+ * added to the pipeline writes to the {@link io.netty.channel. Channel} may happen immediately,
908+ * even before it is active.
913909 */
914910 public static ProtocolNegotiator plaintext () {
915911 return new PlaintextProtocolNegotiator ();
@@ -987,7 +983,7 @@ static final class GrpcNegotiationHandler extends ChannelInboundHandlerAdapter {
987983 private final GrpcHttp2ConnectionHandler next ;
988984
989985 public GrpcNegotiationHandler (GrpcHttp2ConnectionHandler next ) {
990- this .next = checkNotNull (next , "next" );
986+ this .next = Preconditions . checkNotNull (next , "next" );
991987 }
992988
993989 @ Override
@@ -1109,15 +1105,15 @@ static class ProtocolNegotiationHandler extends ChannelDuplexHandler {
11091105
11101106 protected ProtocolNegotiationHandler (ChannelHandler next , String negotiatorName ,
11111107 ChannelLogger negotiationLogger ) {
1112- this .next = checkNotNull (next , "next" );
1108+ this .next = Preconditions . checkNotNull (next , "next" );
11131109 this .negotiatorName = negotiatorName ;
1114- this .negotiationLogger = checkNotNull (negotiationLogger , "negotiationLogger" );
1110+ this .negotiationLogger = Preconditions . checkNotNull (negotiationLogger , "negotiationLogger" );
11151111 }
11161112
11171113 protected ProtocolNegotiationHandler (ChannelHandler next , ChannelLogger negotiationLogger ) {
1118- this .next = checkNotNull (next , "next" );
1114+ this .next = Preconditions . checkNotNull (next , "next" );
11191115 this .negotiatorName = getClass ().getSimpleName ().replace ("Handler" , "" );
1120- this .negotiationLogger = checkNotNull (negotiationLogger , "negotiationLogger" );
1116+ this .negotiationLogger = Preconditions . checkNotNull (negotiationLogger , "negotiationLogger" );
11211117 }
11221118
11231119 @ Override
@@ -1158,7 +1154,7 @@ protected final ProtocolNegotiationEvent getProtocolNegotiationEvent() {
11581154
11591155 protected final void replaceProtocolNegotiationEvent (ProtocolNegotiationEvent pne ) {
11601156 checkState (this .pne != null , "previous protocol negotiation event hasn't triggered" );
1161- this .pne = checkNotNull (pne );
1157+ this .pne = Preconditions . checkNotNull (pne );
11621158 }
11631159
11641160 protected final void fireProtocolNegotiationEvent (ChannelHandlerContext ctx ) {
0 commit comments