cadonna commented on code in PR #18527: URL: https://github.com/apache/kafka/pull/18527#discussion_r1923872395
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/StreamsRebalanceData.java: ########## @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.clients.consumer.internals; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +/** + * This class holds the data that is needed to participate in the Streams rebalance protocol. + */ +public class StreamsRebalanceData { + + public static class Assignment { + + public static final Assignment EMPTY = new Assignment(); + + public final Set<TaskId> activeTasks = new HashSet<>(); + + public final Set<TaskId> standbyTasks = new HashSet<>(); + + public final Set<TaskId> warmupTasks = new HashSet<>(); + + public Assignment() { + } + + public Assignment(final Set<TaskId> activeTasks, + final Set<TaskId> standbyTasks, + final Set<TaskId> warmupTasks) { + this.activeTasks.addAll(activeTasks); + this.standbyTasks.addAll(standbyTasks); + this.warmupTasks.addAll(warmupTasks); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Assignment that = (Assignment) o; + return Objects.equals(activeTasks, that.activeTasks) + && Objects.equals(standbyTasks, that.standbyTasks) + && Objects.equals(warmupTasks, that.warmupTasks); + } + + @Override + public int hashCode() { + return Objects.hash(activeTasks, standbyTasks, warmupTasks); + } + + public Assignment copy() { + return new Assignment(activeTasks, standbyTasks, warmupTasks); + } + + @Override + public String toString() { + return "Assignment{" + + "activeTasks=" + activeTasks + + ", standbyTasks=" + standbyTasks + + ", warmupTasks=" + warmupTasks + + '}'; + } + } + + public static class TaskId implements Comparable<TaskId> { + + private final String subtopologyId; + private final int partitionId; + + public int partitionId() { + return partitionId; + } + + public String subtopologyId() { + return subtopologyId; + } + + public TaskId(final String subtopologyId, final int partitionId) { + this.subtopologyId = subtopologyId; + this.partitionId = partitionId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TaskId taskId = (TaskId) o; + return partitionId == taskId.partitionId && Objects.equals(subtopologyId, taskId.subtopologyId); + } + + @Override + public int hashCode() { + return Objects.hash(subtopologyId, partitionId); + } + + @Override + public int compareTo(TaskId taskId) { + if (subtopologyId.equals(taskId.subtopologyId)) { + return partitionId - taskId.partitionId; + } + return subtopologyId.compareTo(taskId.subtopologyId); + } + + @Override + public String toString() { + return "TaskId{" + + "subtopologyId=" + subtopologyId + + ", partitionId=" + partitionId + + '}'; + } + } + + public static class Subtopology { + + public final Set<String> sourceTopics; + public final Set<String> repartitionSinkTopics; + public final Map<String, TopicInfo> stateChangelogTopics; + public final Map<String, TopicInfo> repartitionSourceTopics; + public final Collection<Set<String>> copartitionGroups; + + public Subtopology(final Set<String> sourceTopics, + final Set<String> repartitionSinkTopics, + final Map<String, TopicInfo> repartitionSourceTopics, + final Map<String, TopicInfo> stateChangelogTopics, + final Collection<Set<String>> copartitionGroups + ) { + this.sourceTopics = sourceTopics; + this.repartitionSinkTopics = repartitionSinkTopics; + this.stateChangelogTopics = stateChangelogTopics; + this.repartitionSourceTopics = repartitionSourceTopics; + this.copartitionGroups = copartitionGroups; + } + + @Override + public String toString() { + return "Subtopology{" + + "sourceTopics=" + sourceTopics + + ", repartitionSinkTopics=" + repartitionSinkTopics + + ", stateChangelogTopics=" + stateChangelogTopics + + ", repartitionSourceTopics=" + repartitionSourceTopics + + ", copartitionGroups=" + copartitionGroups + + '}'; + } + } + + public static class TopicInfo { + + public final Optional<Integer> numPartitions; + public final Optional<Short> replicationFactor; + public final Map<String, String> topicConfigs; + + public TopicInfo(final Optional<Integer> numPartitions, + final Optional<Short> replicationFactor, + final Map<String, String> topicConfigs) { + this.numPartitions = numPartitions; + this.replicationFactor = replicationFactor; + this.topicConfigs = topicConfigs; + } + + @Override + public String toString() { + return "TopicInfo{" + + "numPartitions=" + numPartitions + + ", replicationFactor=" + replicationFactor + + ", topicConfigs=" + topicConfigs + + '}'; + } + } + + private final Map<String, Subtopology> subtopologies; Review Comment: I thought that having first the inner classes and then the fields would be better. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
