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