@@ -155,6 +155,7 @@ enum State {
155155
156156 private final AtomicReference <Owner > ownerRef = new AtomicReference <Owner >();
157157 private final ApplicationInfo applicationInfo ;
158+ private ProtocolFeatureStore protocolFeatureStore ;
158159
159160 /**
160161 * Create a new connection to a Cassandra node and associate it with the given pool.
@@ -449,35 +450,31 @@ private AsyncFunction<Message.Response, Void> onOptionsResponse(
449450 final ProtocolVersion protocolVersion , final Executor initExecutor ) {
450451 return new AsyncFunction <Message .Response , Void >() {
451452 @ Override
452- public ListenableFuture <Void > apply (Message .Response response ) throws Exception {
453+ public ListenableFuture <Void > apply (Message .Response response ) {
453454 switch (response .type ) {
454455 case SUPPORTED :
455- Responses .Supported msg = (Supported ) response ;
456- ShardingInfo .ConnectionShardingInfo sharding =
457- ShardingInfo .parseShardingInfo (msg .supported );
458- if (sharding != null ) {
459- getHost ().setShardingInfo (sharding .shardingInfo );
460- Connection .this .shardId = sharding .shardId ;
456+ Supported supported = (Supported ) response ;
457+ protocolFeatureStore = ProtocolFeatureStore .parseSupportedOptions (supported .supported );
458+ protocolFeatureStore .storeInChannel (channel );
459+ getHost ().setProtocolFeatureStore (protocolFeatureStore );
460+
461+ ShardingInfo .ConnectionShardingInfo shardingInfo =
462+ protocolFeatureStore .getConnectionShardingInfo ();
463+ if (protocolFeatureStore .getConnectionShardingInfo () != null ) {
464+ Connection .this .shardId = shardingInfo .shardId ;
461465 if (Connection .this .requestedShardId != -1
462- && Connection .this .requestedShardId != sharding .shardId ) {
466+ && Connection .this .requestedShardId != shardingInfo .shardId ) {
463467 logger .warn (
464468 "Advanced shard awareness: requested connection to shard {}, but connected to {}. Is there a NAT between client and server?" ,
465469 Connection .this .requestedShardId ,
466- sharding .shardId );
470+ shardingInfo .shardId );
467471 // Owner is a HostConnectionPool if we are using adv. shard awareness
468472 ((HostConnectionPool ) Connection .this .ownerRef .get ())
469473 .tempBlockAdvShardAwareness (ADV_SHARD_AWARENESS_BLOCK_ON_NAT );
470474 }
471475 } else {
472- getHost ().setShardingInfo (null );
473476 Connection .this .shardId = 0 ;
474477 }
475- LwtInfo lwt = LwtInfo .parseLwtInfo (msg .supported );
476- if (lwt != null ) {
477- getHost ().setLwtInfo (lwt );
478- }
479- TabletInfo tabletInfo = TabletInfo .parseTabletInfo (msg .supported );
480- getHost ().setTabletInfo (tabletInfo );
481478 return MoreFutures .VOID_SUCCESS ;
482479 case ERROR :
483480 Responses .Error error = (Responses .Error ) response ;
@@ -506,20 +503,13 @@ private AsyncFunction<Void, Void> onOptionsReady(
506503 @ Override
507504 public ListenableFuture <Void > apply (Void input ) throws Exception {
508505 ProtocolOptions protocolOptions = factory .configuration .getProtocolOptions ();
509- Map <String , String > extraOptions = new HashMap <String , String >();
506+ Map <String , String > extraOptions = new HashMap <>();
510507 if (applicationInfo != null ) {
511508 applicationInfo .addOption (extraOptions );
512509 }
513- LwtInfo lwtInfo = getHost ().getLwtInfo ();
514- if (lwtInfo != null ) {
515- lwtInfo .addOption (extraOptions );
516- }
517- TabletInfo tabletInfo = getHost ().getTabletInfo ();
518- if (tabletInfo != null
519- && tabletInfo .isEnabled ()
520- && ProtocolFeature .CUSTOM_PAYLOADS .isSupportedBy (protocolVersion )) {
521- logger .debug ("Enabling tablet support in OPTIONS message" );
522- TabletInfo .addOption (extraOptions );
510+
511+ if (protocolFeatureStore != null ) {
512+ protocolFeatureStore .populateStartupOptions (protocolVersion , extraOptions );
523513 }
524514
525515 Future startupResponseFuture =
@@ -1065,6 +1055,10 @@ public int shardId() {
10651055 return shardId == null ? 0 : shardId ;
10661056 }
10671057
1058+ public ProtocolFeatureStore getProtocolFeatureStore () {
1059+ return protocolFeatureStore ;
1060+ }
1061+
10681062 /**
10691063 * If the connection is part of a pool, return it to the pool. The connection should generally not
10701064 * be reused after that.
@@ -1955,21 +1949,6 @@ interface DefaultResponseHandler {
19551949 }
19561950
19571951 private static class Initializer extends ChannelInitializer <SocketChannel > {
1958- // Stateless handlers
1959- private static final Message .ProtocolDecoder messageDecoder = new Message .ProtocolDecoder ();
1960- private static final Message .ProtocolEncoder messageEncoderV1 =
1961- new Message .ProtocolEncoder (ProtocolVersion .V1 );
1962- private static final Message .ProtocolEncoder messageEncoderV2 =
1963- new Message .ProtocolEncoder (ProtocolVersion .V2 );
1964- private static final Message .ProtocolEncoder messageEncoderV3 =
1965- new Message .ProtocolEncoder (ProtocolVersion .V3 );
1966- private static final Message .ProtocolEncoder messageEncoderV4 =
1967- new Message .ProtocolEncoder (ProtocolVersion .V4 );
1968- private static final Message .ProtocolEncoder messageEncoderV5 =
1969- new Message .ProtocolEncoder (ProtocolVersion .V5 );
1970- private static final Message .ProtocolEncoder messageEncoderV6 =
1971- new Message .ProtocolEncoder (ProtocolVersion .V6 );
1972- private static final Frame .Encoder frameEncoder = new Frame .Encoder ();
19731952
19741953 private final ProtocolVersion protocolVersion ;
19751954 private final Connection connection ;
@@ -2033,7 +2012,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
20332012 }
20342013
20352014 pipeline .addLast ("frameDecoder" , new Frame .Decoder ());
2036- pipeline .addLast ("frameEncoder" , frameEncoder );
2015+ pipeline .addLast ("frameEncoder" , new Frame . Encoder () );
20372016
20382017 pipeline .addLast ("framingFormatHandler" , new FramingFormatHandler (connection .factory ));
20392018
@@ -2046,7 +2025,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
20462025 pipeline .addLast ("frameCompressor" , new Frame .Compressor (compressor ));
20472026 }
20482027
2049- pipeline .addLast ("messageDecoder" , messageDecoder );
2028+ pipeline .addLast ("messageDecoder" , new Message . ProtocolDecoder ( null ) );
20502029 pipeline .addLast ("messageEncoder" , messageEncoderFor (protocolVersion ));
20512030
20522031 pipeline .addLast ("idleStateHandler" , idleStateHandler );
@@ -2056,23 +2035,11 @@ protected void initChannel(SocketChannel channel) throws Exception {
20562035 nettyOptions .afterChannelInitialized (channel );
20572036 }
20582037
2059- private Message .ProtocolEncoder messageEncoderFor (ProtocolVersion version ) {
2060- switch (version ) {
2061- case V1 :
2062- return messageEncoderV1 ;
2063- case V2 :
2064- return messageEncoderV2 ;
2065- case V3 :
2066- return messageEncoderV3 ;
2067- case V4 :
2068- return messageEncoderV4 ;
2069- case V5 :
2070- return messageEncoderV5 ;
2071- case V6 :
2072- return messageEncoderV6 ;
2073- default :
2074- throw new DriverInternalError ("Unsupported protocol version " + protocolVersion );
2038+ private static Message .ProtocolEncoder messageEncoderFor (ProtocolVersion version ) {
2039+ if (version .toInt () > ProtocolVersion .V6 .toInt ()) {
2040+ throw new DriverInternalError ("Unsupported protocol version " + version );
20752041 }
2042+ return new Message .ProtocolEncoder (version , null );
20762043 }
20772044 }
20782045
0 commit comments