|
25 | 25 | import java.util.Map;
|
26 | 26 | import java.util.Objects;
|
27 | 27 | import java.util.concurrent.atomic.AtomicInteger;
|
28 |
| -import java.util.stream.Collectors; |
29 | 28 |
|
30 | 29 | import org.apache.kafka.common.Metric;
|
31 | 30 | import org.apache.kafka.common.MetricName;
|
@@ -120,12 +119,12 @@ public void setAlwaysClientIdSuffix(boolean alwaysClientIdSuffix) {
|
120 | 119 | public List<KafkaMessageListenerContainer<K, V>> getContainers() {
|
121 | 120 | this.lifecycleLock.lock();
|
122 | 121 | try {
|
123 |
| - return Collections.unmodifiableList(new ArrayList<>(this.containers)); |
| 122 | + return List.copyOf(this.containers); |
124 | 123 | }
|
125 | 124 | finally {
|
126 | 125 | this.lifecycleLock.unlock();
|
127 | 126 | }
|
128 |
| -} |
| 127 | + } |
129 | 128 |
|
130 | 129 | @Override
|
131 | 130 | public MessageListenerContainer getContainerFor(String topic, int partition) {
|
@@ -156,7 +155,7 @@ public Collection<TopicPartition> getAssignedPartitions() {
|
156 | 155 | .map(KafkaMessageListenerContainer::getAssignedPartitions)
|
157 | 156 | .filter(Objects::nonNull)
|
158 | 157 | .flatMap(Collection::stream)
|
159 |
| - .collect(Collectors.toList()); |
| 158 | + .toList(); |
160 | 159 | }
|
161 | 160 | finally {
|
162 | 161 | this.lifecycleLock.unlock();
|
@@ -258,7 +257,6 @@ protected void doStart() {
|
258 | 257 | }
|
259 | 258 | }
|
260 | 259 |
|
261 |
| - @SuppressWarnings("deprecation") |
262 | 260 | private void configureChildContainer(int index, KafkaMessageListenerContainer<K, V> container) {
|
263 | 261 | String beanName = getBeanName();
|
264 | 262 | beanName = (beanName == null ? "consumer" : beanName) + "-" + index;
|
@@ -307,13 +305,17 @@ private KafkaMessageListenerContainer<K, V> constructContainer(ContainerProperti
|
307 | 305 | return container;
|
308 | 306 | }
|
309 | 307 |
|
| 308 | + @Nullable |
310 | 309 | private TopicPartitionOffset[] partitionSubset(ContainerProperties containerProperties, int index) {
|
311 | 310 | TopicPartitionOffset[] topicPartitions = containerProperties.getTopicPartitions();
|
| 311 | + if (topicPartitions == null) { |
| 312 | + return null; |
| 313 | + } |
312 | 314 | if (this.concurrency == 1) {
|
313 |
| - return topicPartitions; // NOSONAR |
| 315 | + return topicPartitions; |
314 | 316 | }
|
315 | 317 | else {
|
316 |
| - int numPartitions = topicPartitions.length; // NOSONAR |
| 318 | + int numPartitions = topicPartitions.length; |
317 | 319 | if (numPartitions == this.concurrency) {
|
318 | 320 | return new TopicPartitionOffset[] { topicPartitions[index] };
|
319 | 321 | }
|
@@ -388,7 +390,7 @@ && getContainerProperties().isRestartAfterAuthExceptions()
|
388 | 390 | if (exec == null) {
|
389 | 391 | exec = new SimpleAsyncTaskExecutor(getListenerId() + ".authRestart");
|
390 | 392 | }
|
391 |
| - exec.execute(() -> start()); |
| 393 | + exec.execute(this::start); |
392 | 394 | }
|
393 | 395 | }
|
394 | 396 |
|
@@ -476,10 +478,15 @@ public boolean isPartitionPaused(TopicPartition topicPartition) {
|
476 | 478 | public boolean isInExpectedState() {
|
477 | 479 | this.lifecycleLock.lock();
|
478 | 480 | try {
|
479 |
| - return (isRunning() || isStoppedNormally()) && this.containers |
480 |
| - .stream() |
481 |
| - .map(container -> container.isInExpectedState()) |
482 |
| - .allMatch(bool -> Boolean.TRUE.equals(bool)); |
| 481 | + boolean isInExpectedState = isRunning() || isStoppedNormally(); |
| 482 | + if (isInExpectedState) { |
| 483 | + for (KafkaMessageListenerContainer<K, V> container : this.containers) { |
| 484 | + if (!container.isInExpectedState()) { |
| 485 | + return false; |
| 486 | + } |
| 487 | + } |
| 488 | + } |
| 489 | + return isInExpectedState; |
483 | 490 | }
|
484 | 491 | finally {
|
485 | 492 | this.lifecycleLock.unlock();
|
|
0 commit comments