Skip to content

Commit 15474e0

Browse files
authored
MINOR: Cleanup Server Common Module (apache#19085)
Given that now we support Java 17 on our brokers, this PR replace the use of the following in server-common module: - Collections.singletonList() and Collections.emptyList() with List.of() - Collections.singletonMap() and Collections.emptyMap() with Map.of() - Collections.singleton() and Collections.emptySet() with Set.of() - Arrays.asList() with List.of() Reviewers: Chia-Ping Tsai <[email protected]>
1 parent 20bad6e commit 15474e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+323
-363
lines changed

server-common/src/main/java/org/apache/kafka/server/common/CheckpointFile.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.nio.file.Paths;
3232
import java.util.ArrayList;
3333
import java.util.Collection;
34-
import java.util.Collections;
3534
import java.util.List;
3635
import java.util.Optional;
3736

@@ -146,7 +145,7 @@ public CheckpointReadBuffer(String location,
146145
public List<T> read() throws IOException {
147146
String line = reader.readLine();
148147
if (line == null)
149-
return Collections.emptyList();
148+
return List.of();
150149

151150
int readVersion = toInt(line);
152151
if (readVersion != version) {
@@ -156,7 +155,7 @@ public List<T> read() throws IOException {
156155

157156
line = reader.readLine();
158157
if (line == null) {
159-
return Collections.emptyList();
158+
return List.of();
160159
}
161160
int expectedSize = toInt(line);
162161
List<T> entries = new ArrayList<>(expectedSize);

server-common/src/main/java/org/apache/kafka/server/common/EligibleLeaderReplicasVersion.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
public enum EligibleLeaderReplicasVersion implements FeatureVersion {
2322

2423
// Version 0 is the version disable ELR.
25-
ELRV_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
24+
ELRV_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
2625

2726
// Version 1 enables the ELR (KIP-966).
2827
ELRV_1(1, MetadataVersion.IBP_4_1_IV0, Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_4_0_IV1.featureLevel()));

server-common/src/main/java/org/apache/kafka/server/common/FinalizedFeatures.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.HashMap;
2120
import java.util.Map;
2221
import java.util.Objects;
@@ -27,7 +26,7 @@ public record FinalizedFeatures(
2726
long finalizedFeaturesEpoch
2827
) {
2928
public static FinalizedFeatures fromKRaftVersion(MetadataVersion version) {
30-
return new FinalizedFeatures(version, Collections.emptyMap(), -1);
29+
return new FinalizedFeatures(version, Map.of(), -1);
3130
}
3231

3332
public FinalizedFeatures(

server-common/src/main/java/org/apache/kafka/server/common/GroupVersion.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
public enum GroupVersion implements FeatureVersion {
2322

2423
// Version 0 is the original group coordinator prior to KIP-848.
25-
GV_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
24+
GV_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
2625

2726
// Version 1 enables the consumer rebalance protocol (KIP-848).
28-
GV_1(1, MetadataVersion.IBP_4_0_IV0, Collections.emptyMap());
27+
GV_1(1, MetadataVersion.IBP_4_0_IV0, Map.of());
2928

3029
public static final String FEATURE_NAME = "group.version";
3130

server-common/src/main/java/org/apache/kafka/server/common/KRaftVersion.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
public enum KRaftVersion implements FeatureVersion {
@@ -74,9 +73,9 @@ public MetadataVersion bootstrapMetadataVersion() {
7473
@Override
7574
public Map<String, Short> dependencies() {
7675
if (this.featureLevel == 0) {
77-
return Collections.emptyMap();
76+
return Map.of();
7877
} else {
79-
return Collections.singletonMap(
78+
return Map.of(
8079
MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_9_IV0.featureLevel());
8180
}
8281
}

server-common/src/main/java/org/apache/kafka/server/common/TestFeatureVersion.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
public enum TestFeatureVersion implements FeatureVersion {
23-
TEST_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
22+
TEST_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
2423
// TEST_1 released right before MV 3.7-IVO was released, and it has no dependencies
25-
TEST_1(1, MetadataVersion.IBP_3_7_IV0, Collections.emptyMap()),
24+
TEST_1(1, MetadataVersion.IBP_3_7_IV0, Map.of()),
2625
// TEST_2 is not yet set to be the default version and maps to the latest testing version, and it depends on this metadata version
27-
TEST_2(2, MetadataVersion.latestTesting(), Collections.singletonMap(MetadataVersion.FEATURE_NAME, MetadataVersion.latestTesting().featureLevel()));
26+
TEST_2(2, MetadataVersion.latestTesting(), Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.latestTesting().featureLevel()));
2827

2928
private final short featureLevel;
3029
private final MetadataVersion metadataVersionMapping;

server-common/src/main/java/org/apache/kafka/server/common/TransactionVersion.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
import org.apache.kafka.common.requests.AddPartitionsToTxnRequest;
2020
import org.apache.kafka.common.requests.EndTxnRequest;
2121

22-
import java.util.Collections;
2322
import java.util.Map;
2423

2524
public enum TransactionVersion implements FeatureVersion {
2625

2726
// Version 0 is the original transaction coordinator with no extra features enabled.
28-
TV_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
27+
TV_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
2928
// Version 1 enables flexible transactional state records. (KIP-890)
30-
TV_1(1, MetadataVersion.IBP_4_0_IV2, Collections.emptyMap()),
29+
TV_1(1, MetadataVersion.IBP_4_0_IV2, Map.of()),
3130
// Version 2 enables epoch bump per transaction and optimizations. (KIP-890)
32-
TV_2(2, MetadataVersion.IBP_4_0_IV2, Collections.emptyMap());
31+
TV_2(2, MetadataVersion.IBP_4_0_IV2, Map.of());
3332

3433
public static final String FEATURE_NAME = "transaction.version";
3534

server-common/src/main/java/org/apache/kafka/server/common/UnitTestFeatureVersion.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.apache.kafka.server.common;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
/**
@@ -27,8 +26,8 @@ public class UnitTestFeatureVersion {
2726
* The feature is used for testing latest production is not one of the feature versions.
2827
*/
2928
public enum FV0 implements FeatureVersion {
30-
UT_FV0_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
31-
UT_FV0_1(1, MetadataVersion.IBP_3_7_IV0, Collections.emptyMap());
29+
UT_FV0_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
30+
UT_FV0_1(1, MetadataVersion.IBP_3_7_IV0, Map.of());
3231

3332
private final short featureLevel;
3433
private final MetadataVersion bootstrapMetadataVersion;
@@ -69,8 +68,8 @@ public Map<String, Short> dependencies() {
6968
* The feature is used to test latest production lags behind the default value.
7069
*/
7170
public enum FV1 implements FeatureVersion {
72-
UT_FV1_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
73-
UT_FV1_1(1, MetadataVersion.IBP_3_7_IV0, Collections.emptyMap());
71+
UT_FV1_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
72+
UT_FV1_1(1, MetadataVersion.IBP_3_7_IV0, Map.of());
7473

7574
private final short featureLevel;
7675
private final MetadataVersion bootstrapMetadataVersion;
@@ -111,8 +110,8 @@ public Map<String, Short> dependencies() {
111110
* The feature is used to test the dependency of the latest production that is not yet production ready.
112111
*/
113112
public enum FV2 implements FeatureVersion {
114-
UT_FV2_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
115-
UT_FV2_1(1, MetadataVersion.IBP_3_7_IV0, Collections.emptyMap());
113+
UT_FV2_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
114+
UT_FV2_1(1, MetadataVersion.IBP_3_7_IV0, Map.of());
116115

117116
private final short featureLevel;
118117
private final MetadataVersion bootstrapMetadataVersion;
@@ -153,8 +152,8 @@ public Map<String, Short> dependencies() {
153152
* The feature is used to test the dependency of the latest production that is not yet production ready.
154153
*/
155154
public enum FV3 implements FeatureVersion {
156-
UT_FV3_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
157-
UT_FV3_1(1, MetadataVersion.IBP_3_7_IV0, Collections.singletonMap(FV2.FEATURE_NAME, (short) 1));
155+
UT_FV3_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
156+
UT_FV3_1(1, MetadataVersion.IBP_3_7_IV0, Map.of(FV2.FEATURE_NAME, (short) 1));
158157

159158
private final short featureLevel;
160159
private final MetadataVersion bootstrapMetadataVersion;
@@ -195,8 +194,8 @@ public Map<String, Short> dependencies() {
195194
* The feature is used to test the dependency of the default value that is not yet default ready.
196195
*/
197196
public enum FV4 implements FeatureVersion {
198-
UT_FV4_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
199-
UT_FV4_1(1, MetadataVersion.latestTesting(), Collections.emptyMap());
197+
UT_FV4_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
198+
UT_FV4_1(1, MetadataVersion.latestTesting(), Map.of());
200199

201200
private final short featureLevel;
202201
private final MetadataVersion bootstrapMetadataVersion;
@@ -237,8 +236,8 @@ public Map<String, Short> dependencies() {
237236
* The feature is used to test the dependency of the default value that is not yet default ready.
238237
*/
239238
public enum FV5 implements FeatureVersion {
240-
UT_FV5_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
241-
UT_FV5_1(1, MetadataVersion.IBP_3_7_IV0, Collections.singletonMap(FV4.FEATURE_NAME, (short) 1));
239+
UT_FV5_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
240+
UT_FV5_1(1, MetadataVersion.IBP_3_7_IV0, Map.of(FV4.FEATURE_NAME, (short) 1));
242241

243242
private final short featureLevel;
244243
private final MetadataVersion bootstrapMetadataVersion;
@@ -279,8 +278,8 @@ public Map<String, Short> dependencies() {
279278
* The feature is used to test the latest production has MV dependency that is not yet production ready.
280279
*/
281280
public enum FV6 implements FeatureVersion {
282-
UT_FV6_0(0, MetadataVersion.MINIMUM_VERSION, Collections.emptyMap()),
283-
UT_FV6_1(1, MetadataVersion.latestTesting(), Collections.singletonMap(MetadataVersion.FEATURE_NAME, MetadataVersion.latestTesting().featureLevel()));
281+
UT_FV6_0(0, MetadataVersion.MINIMUM_VERSION, Map.of()),
282+
UT_FV6_1(1, MetadataVersion.latestTesting(), Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.latestTesting().featureLevel()));
284283

285284
private final short featureLevel;
286285
private final MetadataVersion bootstrapMetadataVersion;
@@ -321,8 +320,8 @@ public Map<String, Short> dependencies() {
321320
* The feature is used to test the default value has MV dependency that is behind the bootstrap MV.
322321
*/
323322
public enum FV7 implements FeatureVersion {
324-
UT_FV7_0(0, MetadataVersion.MINIMUM_VERSION, Collections.singletonMap(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_7_IV0.featureLevel())),
325-
UT_FV7_1(1, MetadataVersion.IBP_3_8_IV0, Collections.singletonMap(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_8_IV0.featureLevel()));
323+
UT_FV7_0(0, MetadataVersion.MINIMUM_VERSION, Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_7_IV0.featureLevel())),
324+
UT_FV7_1(1, MetadataVersion.IBP_3_8_IV0, Map.of(MetadataVersion.FEATURE_NAME, MetadataVersion.IBP_3_8_IV0.featureLevel()));
326325

327326
private final short featureLevel;
328327
private final MetadataVersion bootstrapMetadataVersion;

server-common/src/main/java/org/apache/kafka/server/config/QuotaConfig.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.kafka.common.config.ConfigDef;
2121
import org.apache.kafka.common.security.scram.internals.ScramMechanism;
2222

23-
import java.util.Collections;
2423
import java.util.List;
2524
import java.util.Set;
2625

@@ -62,14 +61,14 @@ public class QuotaConfig {
6261
"the leader side. The list should describe a set of replicas in the form " +
6362
"[PartitionId]:[BrokerId],[PartitionId]:[BrokerId]:... or alternatively the wildcard '*' can be used to throttle " +
6463
"all replicas for this topic.";
65-
public static final List<String> LEADER_REPLICATION_THROTTLED_REPLICAS_DEFAULT = Collections.emptyList();
64+
public static final List<String> LEADER_REPLICATION_THROTTLED_REPLICAS_DEFAULT = List.of();
6665

6766
public static final String FOLLOWER_REPLICATION_THROTTLED_REPLICAS_CONFIG = "follower.replication.throttled.replicas";
6867
public static final String FOLLOWER_REPLICATION_THROTTLED_REPLICAS_DOC = "A list of replicas for which log replication should be throttled on " +
6968
"the follower side. The list should describe a set of " + "replicas in the form " +
7069
"[PartitionId]:[BrokerId],[PartitionId]:[BrokerId]:... or alternatively the wildcard '*' can be used to throttle " +
7170
"all replicas for this topic.";
72-
public static final List<String> FOLLOWER_REPLICATION_THROTTLED_REPLICAS_DEFAULT = Collections.emptyList();
71+
public static final List<String> FOLLOWER_REPLICATION_THROTTLED_REPLICAS_DEFAULT = List.of();
7372

7473

7574
public static final String LEADER_REPLICATION_THROTTLED_RATE_CONFIG = "leader.replication.throttled.rate";

server-common/src/main/java/org/apache/kafka/server/config/ServerTopicConfigSynonyms.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@
2020
import org.apache.kafka.common.utils.Utils;
2121

2222
import java.util.Arrays;
23-
import java.util.Collections;
2423
import java.util.List;
2524
import java.util.Map;
2625
import java.util.Map.Entry;
2726
import java.util.NoSuchElementException;
2827
import java.util.stream.Collectors;
2928

30-
import static java.util.Arrays.asList;
3129

3230
public final class ServerTopicConfigSynonyms {
3331
public static final String LOG_PREFIX = "log.";
@@ -50,7 +48,7 @@ public final class ServerTopicConfigSynonyms {
5048
* the first synonym and ignore the second.
5149
*/
5250
// Topic configs with no mapping to a server config can be found in `LogConfig.CONFIGS_WITH_NO_SERVER_DEFAULTS`
53-
public static final Map<String, List<ConfigSynonym>> ALL_TOPIC_CONFIG_SYNONYMS = Collections.unmodifiableMap(Utils.mkMap(
51+
public static final Map<String, List<ConfigSynonym>> ALL_TOPIC_CONFIG_SYNONYMS = Utils.mkMap(
5452
sameNameWithLogPrefix(TopicConfig.SEGMENT_BYTES_CONFIG),
5553
listWithLogPrefix(TopicConfig.SEGMENT_MS_CONFIG,
5654
new ConfigSynonym("roll.ms"),
@@ -88,17 +86,17 @@ public final class ServerTopicConfigSynonyms {
8886
sameNameWithLogPrefix(TopicConfig.MESSAGE_TIMESTAMP_AFTER_MAX_MS_CONFIG),
8987
sameNameWithLogPrefix(TopicConfig.LOCAL_LOG_RETENTION_MS_CONFIG),
9088
sameNameWithLogPrefix(TopicConfig.LOCAL_LOG_RETENTION_BYTES_CONFIG)
91-
));
89+
);
9290

9391
/**
9492
* Map topic config to the server config with the highest priority. Some of these have additional
9593
* synonyms that can be obtained using [[kafka.server.DynamicBrokerConfig#brokerConfigSynonyms]]
9694
* or using [[AllTopicConfigSynonyms]]
9795
*/
98-
public static final Map<String, String> TOPIC_CONFIG_SYNONYMS = Collections.unmodifiableMap(
96+
public static final Map<String, String> TOPIC_CONFIG_SYNONYMS =
9997
ALL_TOPIC_CONFIG_SYNONYMS.entrySet()
10098
.stream()
101-
.collect(Collectors.toMap(Entry::getKey, e -> e.getValue().get(0).name())));
99+
.collect(Collectors.toMap(Entry::getKey, e -> e.getValue().get(0).name()));
102100

103101
/**
104102
* Return the server config with the highest priority for `topicConfigName` if it exists. Otherwise,
@@ -112,23 +110,23 @@ public static String serverSynonym(String topicConfigName) {
112110
}
113111

114112
private static Entry<String, List<ConfigSynonym>> sameName(String configName) {
115-
return Utils.mkEntry(configName, asList(new ConfigSynonym(configName)));
113+
return Utils.mkEntry(configName, List.of(new ConfigSynonym(configName)));
116114
}
117115

118116
private static Entry<String, List<ConfigSynonym>> sameNameWithLogPrefix(String configName) {
119-
return Utils.mkEntry(configName, asList(new ConfigSynonym(LOG_PREFIX + configName)));
117+
return Utils.mkEntry(configName, List.of(new ConfigSynonym(LOG_PREFIX + configName)));
120118
}
121119

122120
private static Entry<String, List<ConfigSynonym>> sameNameWithLogCleanerPrefix(String configName) {
123-
return Utils.mkEntry(configName, asList(new ConfigSynonym(LOG_CLEANER_PREFIX + configName)));
121+
return Utils.mkEntry(configName, List.of(new ConfigSynonym(LOG_CLEANER_PREFIX + configName)));
124122
}
125123

126124
private static Entry<String, List<ConfigSynonym>> singleWithLogPrefix(String topicConfigName, String brokerConfigName) {
127-
return Utils.mkEntry(topicConfigName, asList(new ConfigSynonym(LOG_PREFIX + brokerConfigName)));
125+
return Utils.mkEntry(topicConfigName, List.of(new ConfigSynonym(LOG_PREFIX + brokerConfigName)));
128126
}
129127

130128
private static Entry<String, List<ConfigSynonym>> singleWithLogCleanerPrefix(String topicConfigName, String brokerConfigName) {
131-
return Utils.mkEntry(topicConfigName, asList(new ConfigSynonym(LOG_CLEANER_PREFIX + brokerConfigName)));
129+
return Utils.mkEntry(topicConfigName, List.of(new ConfigSynonym(LOG_CLEANER_PREFIX + brokerConfigName)));
132130
}
133131

134132
private static Entry<String, List<ConfigSynonym>> listWithLogPrefix(String topicConfigName, ConfigSynonym... synonyms) {
@@ -139,6 +137,6 @@ private static Entry<String, List<ConfigSynonym>> listWithLogPrefix(String topic
139137
}
140138

141139
private static Entry<String, List<ConfigSynonym>> single(String topicConfigName, String brokerConfigName) {
142-
return Utils.mkEntry(topicConfigName, asList(new ConfigSynonym(brokerConfigName)));
140+
return Utils.mkEntry(topicConfigName, List.of(new ConfigSynonym(brokerConfigName)));
143141
}
144142
}

0 commit comments

Comments
 (0)