Skip to content

Commit c815f46

Browse files
committed
Implement ProtocolFeatureStore
Implement class to store information about all features negotiated.
1 parent 6932f11 commit c815f46

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/channel/DriverChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.datastax.oss.driver.internal.core.adminrequest.ThrottledAdminRequestHandler;
3333
import com.datastax.oss.driver.internal.core.pool.ChannelPool;
3434
import com.datastax.oss.driver.internal.core.protocol.LwtInfo;
35+
import com.datastax.oss.driver.internal.core.protocol.ProtocolFeatureStore;
3536
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo;
3637
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo.ConnectionShardingInfo;
3738
import com.datastax.oss.driver.internal.core.session.DefaultSession;
@@ -63,7 +64,6 @@ public class DriverChannel {
6364
AttributeKey.valueOf("options");
6465
static final AttributeKey<ConnectionShardingInfo> SHARDING_INFO_KEY =
6566
AttributeKey.valueOf("sharding_info");
66-
static final AttributeKey<LwtInfo> LWT_INFO_KEY = AttributeKey.valueOf("lwt_info");
6767

6868
@SuppressWarnings("RedundantStringConstructorCall")
6969
static final Object GRACEFUL_CLOSE_MESSAGE = new String("GRACEFUL_CLOSE_MESSAGE");
@@ -159,7 +159,7 @@ public ShardingInfo getShardingInfo() {
159159
}
160160

161161
public LwtInfo getLwtInfo() {
162-
return channel.attr(LWT_INFO_KEY).get();
162+
return ProtocolFeatureStore.loadFromChannel(channel).getLwtFeatureInfo();
163163
}
164164

165165
/**

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ProtocolInitHandler.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
package com.datastax.oss.driver.internal.core.channel;
2525

26-
import static com.datastax.oss.driver.internal.core.channel.DriverChannel.LWT_INFO_KEY;
27-
2826
import com.datastax.oss.driver.api.core.DefaultProtocolVersion;
2927
import com.datastax.oss.driver.api.core.InvalidKeyspaceException;
3028
import com.datastax.oss.driver.api.core.ProtocolVersion;
@@ -41,6 +39,7 @@
4139
import com.datastax.oss.driver.internal.core.protocol.BytesToSegmentDecoder;
4240
import com.datastax.oss.driver.internal.core.protocol.FrameToSegmentEncoder;
4341
import com.datastax.oss.driver.internal.core.protocol.LwtInfo;
42+
import com.datastax.oss.driver.internal.core.protocol.ProtocolFeatureStore;
4443
import com.datastax.oss.driver.internal.core.protocol.SegmentToBytesEncoder;
4544
import com.datastax.oss.driver.internal.core.protocol.SegmentToFrameDecoder;
4645
import com.datastax.oss.driver.internal.core.protocol.ShardingInfo;
@@ -96,7 +95,7 @@ class ProtocolInitHandler extends ConnectInitHandler {
9695
private String logPrefix;
9796
private ChannelHandlerContext ctx;
9897
private final boolean querySupportedOptions;
99-
private LwtInfo lwtInfo;
98+
private ProtocolFeatureStore featureStore;
10099
private TabletInfo tabletInfo;
101100

102101
/**
@@ -192,9 +191,7 @@ Message getRequest() {
192191
return request = Options.INSTANCE;
193192
case STARTUP:
194193
Map<String, String> startupOptions = new HashMap<>(context.getStartupOptions());
195-
if (lwtInfo != null) {
196-
lwtInfo.addOption(startupOptions);
197-
}
194+
featureStore.populateStartupOptions(startupOptions);
198195
if (tabletInfo != null && tabletInfo.isEnabled()) {
199196
TabletInfo.addOption(startupOptions);
200197
}
@@ -229,15 +226,13 @@ void onResponse(Message response) {
229226
if (step == Step.OPTIONS && response instanceof Supported) {
230227
channel.attr(DriverChannel.OPTIONS_KEY).set(((Supported) response).options);
231228
Supported res = (Supported) response;
229+
featureStore = ProtocolFeatureStore.parseSupportedOptions(res.options);
232230
ConnectionShardingInfo shardingInfo = ShardingInfo.parseShardingInfo(res.options);
233231
if (shardingInfo != null) {
234232
channel.attr(DriverChannel.SHARDING_INFO_KEY).set(shardingInfo);
235233
}
236-
lwtInfo = LwtInfo.parseLwtInfo(res.options);
237-
if (lwtInfo != null) {
238-
channel.attr(LWT_INFO_KEY).set(lwtInfo);
239-
}
240234
tabletInfo = TabletInfo.parseTabletInfo(res.options);
235+
featureStore.storeInChannel(channel);
241236
step = Step.STARTUP;
242237
send();
243238
} else if (step == Step.STARTUP && response instanceof Ready) {

core/src/main/java/com/datastax/oss/driver/internal/core/protocol/LwtInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean isLwt(int flags) {
3737
return (flags & mask) == mask;
3838
}
3939

40-
public static LwtInfo parseLwtInfo(Map<String, List<String>> supported) {
40+
public static LwtInfo loadFromSupportedOptions(Map<String, List<String>> supported) {
4141
if (!supported.containsKey(SCYLLA_LWT_ADD_METADATA_MARK_KEY)) {
4242
return null;
4343
}
@@ -67,7 +67,7 @@ public static LwtInfo parseLwtInfo(Map<String, List<String>> supported) {
6767
return new LwtInfo((int) mask);
6868
}
6969

70-
public void addOption(Map<String, String> options) {
70+
public void populateStartupOptions(Map<String, String> options) {
7171
options.put(SCYLLA_LWT_ADD_METADATA_MARK_KEY, Integer.toString(mask));
7272
}
7373
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.datastax.oss.driver.internal.core.protocol;
2+
3+
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import io.netty.channel.Channel;
5+
import io.netty.util.AttributeKey;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
public class ProtocolFeatureStore {
10+
private static final AttributeKey<ProtocolFeatureStore> CHANNEL_KEY =
11+
AttributeKey.valueOf("protocol_feature_store");
12+
13+
private final LwtInfo lwtInfo;
14+
15+
ProtocolFeatureStore(LwtInfo lwtInfo) {
16+
this.lwtInfo = lwtInfo;
17+
}
18+
19+
public LwtInfo getLwtFeatureInfo() {
20+
return lwtInfo;
21+
}
22+
23+
public static ProtocolFeatureStore parseSupportedOptions(Map<String, List<String>> options) {
24+
LwtInfo lwtInfo = LwtInfo.loadFromSupportedOptions(options);
25+
return new ProtocolFeatureStore(lwtInfo);
26+
}
27+
28+
public void populateStartupOptions(Map<String, String> options) {
29+
if (lwtInfo != null) {
30+
lwtInfo.populateStartupOptions(options);
31+
}
32+
}
33+
34+
public static ProtocolFeatureStore loadFromChannel(@NonNull Channel channel) {
35+
return channel.attr(ProtocolFeatureStore.CHANNEL_KEY).get();
36+
}
37+
38+
public void storeInChannel(@NonNull Channel channel) {
39+
channel.attr(ProtocolFeatureStore.CHANNEL_KEY).set(this);
40+
}
41+
}

0 commit comments

Comments
 (0)