Skip to content

Commit dfed795

Browse files
authored
Fix PartitionedDispatcher to use List for partitions (spring-projects#10290)
The `partitions` map in the `PartitionedDispatcher` is based on the index for `key`, which is really an overkill and regular list with indexed access should be enough. * Fix `PartitionedDispatcher` to use a `List` for `partitions` * Remove `@SuppressWarnings("NullAway")` from `dispatch()` method since there is not going to be a null from `List.get()`
1 parent 9d17e37 commit dfed795

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dispatcher/PartitionedDispatcher.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package org.springframework.integration.dispatcher;
1818

1919
import java.util.ArrayList;
20-
import java.util.HashMap;
2120
import java.util.List;
22-
import java.util.Map;
2321
import java.util.Set;
2422
import java.util.concurrent.Executor;
2523
import java.util.concurrent.ExecutorService;
@@ -60,7 +58,7 @@
6058
*/
6159
public class PartitionedDispatcher extends AbstractDispatcher {
6260

63-
private final Map<Integer, UnicastingDispatcher> partitions = new HashMap<>();
61+
private final List<UnicastingDispatcher> partitions = new ArrayList<>();
6462

6563
private final List<ExecutorService> executors = new ArrayList<>();
6664

@@ -164,7 +162,6 @@ public void shutdown() {
164162
}
165163

166164
@Override
167-
@SuppressWarnings("NullAway") // The partitions map never returns null according to partition hash
168165
public boolean dispatch(Message<?> message) {
169166
populatedPartitions();
170167
int partition = Math.abs(this.partitionKeyFunction.apply(message).hashCode()) % this.partitionCount;
@@ -177,11 +174,9 @@ private void populatedPartitions() {
177174
this.lock.lock();
178175
try {
179176
if (this.partitions.isEmpty()) {
180-
Map<Integer, UnicastingDispatcher> partitionsToUse = new HashMap<>();
181177
for (int i = 0; i < this.partitionCount; i++) {
182-
partitionsToUse.put(i, newPartition());
178+
this.partitions.add(newPartition());
183179
}
184-
this.partitions.putAll(partitionsToUse);
185180
}
186181
}
187182
finally {

0 commit comments

Comments
 (0)