1818
1919import static com .google .common .base .Preconditions .checkState ;
2020
21- import com .google .common .annotations .VisibleForTesting ;
2221import io .grpc .Attributes ;
2322import io .grpc .ChannelLogger ;
2423import io .grpc .Internal ;
2827import io .netty .handler .codec .http2 .Http2ConnectionEncoder ;
2928import io .netty .handler .codec .http2 .Http2ConnectionHandler ;
3029import io .netty .handler .codec .http2 .Http2Settings ;
31- import io .netty .util .Version ;
3230import javax .annotation .Nullable ;
3331
3432/**
3533 * gRPC wrapper for {@link Http2ConnectionHandler}.
3634 */
3735@ Internal
3836public abstract class GrpcHttp2ConnectionHandler extends Http2ConnectionHandler {
39- static final int ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT = 1024 ;
40- static final Cumulator ADAPTIVE_CUMULATOR =
41- new NettyAdaptiveCumulator (ADAPTIVE_CUMULATOR_COMPOSE_MIN_SIZE_DEFAULT );
42-
4337 @ Nullable
4438 protected final ChannelPromise channelUnused ;
4539 private final ChannelLogger negotiationLogger ;
46- private static final boolean usingPre4_1_111_Netty ;
47-
48- static {
49- // Netty 4.1.111 introduced a change in the behavior of duplicate() method
50- // that breaks the assumption of the cumulator. We need to detect this version
51- // and adjust the behavior accordingly.
52-
53- boolean identifiedOldVersion = false ;
54- try {
55- Version version = Version .identify ().get ("netty-buffer" );
56- if (version != null ) {
57- String [] split = version .artifactVersion ().split ("\\ ." );
58- if (split .length >= 3
59- && Integer .parseInt (split [0 ]) == 4
60- && Integer .parseInt (split [1 ]) <= 1
61- && Integer .parseInt (split [2 ]) < 111 ) {
62- identifiedOldVersion = true ;
63- }
64- }
65- } catch (Exception e ) {
66- // Ignore, we'll assume it's a new version.
67- }
68- usingPre4_1_111_Netty = identifiedOldVersion ;
69- }
7040
7141 @ SuppressWarnings ("this-escape" )
7242 protected GrpcHttp2ConnectionHandler (
@@ -78,16 +48,6 @@ protected GrpcHttp2ConnectionHandler(
7848 super (decoder , encoder , initialSettings );
7949 this .channelUnused = channelUnused ;
8050 this .negotiationLogger = negotiationLogger ;
81- if (usingPre4_1_111_Netty ()) {
82- // We need to use the adaptive cumulator only if we're using a version of Netty that
83- // doesn't have the behavior that breaks it.
84- setCumulator (ADAPTIVE_CUMULATOR );
85- }
86- }
87-
88- @ VisibleForTesting
89- static boolean usingPre4_1_111_Netty () {
90- return usingPre4_1_111_Netty ;
9151 }
9252
9353 /**
0 commit comments