Skip to content

Commit 7e263aa

Browse files
artembilangaryrussell
authored andcommitted
GH-2301: Add SimpMessageGrFactory.GroupType.LIST
Fixes #2301 * For non-ordered, without deduplication logic use-case the `ArrayList` option for internal `SimpleMessageGroup` collection is added * Make `SimpleMessageGroup` `protected` ctor as `public` for better reuse in case of custom `MessageGroupFactory`
1 parent 86c7699 commit 7e263aa

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageGroup.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -71,11 +71,12 @@ public SimpleMessageGroup(MessageGroup messageGroup) {
7171

7272
public SimpleMessageGroup(Collection<? extends Message<?>> messages, Object groupId, long timestamp,
7373
boolean complete) {
74-
this(new LinkedHashSet<Message<?>>(), messages, groupId, timestamp, complete, false);
74+
this(new LinkedHashSet<>(), messages, groupId, timestamp, complete, false);
7575
}
7676

77-
protected SimpleMessageGroup(Collection<Message<?>> internalStore, Collection<? extends Message<?>> messages,
77+
public SimpleMessageGroup(Collection<Message<?>> internalStore, Collection<? extends Message<?>> messages,
7878
Object groupId, long timestamp, boolean complete, boolean storePreLoaded) {
79+
7980
Assert.notNull(internalStore, "'internalStore' must not be null");
8081
this.messages = internalStore;
8182
this.groupId = groupId;

spring-integration-core/src/main/java/org/springframework/integration/store/SimpleMessageGroupFactory.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.integration.store;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collection;
2021
import java.util.Collections;
2122
import java.util.LinkedHashSet;
@@ -29,6 +30,7 @@
2930
* The {@link GroupType#HASH_SET} is the default type.
3031
*
3132
* @author Artem Bilan
33+
*
3234
* @since 4.3
3335
*/
3436
public class SimpleMessageGroupFactory implements MessageGroupFactory {
@@ -45,7 +47,7 @@ public SimpleMessageGroupFactory(GroupType type) {
4547

4648
@Override
4749
public MessageGroup create(Object groupId) {
48-
return create(Collections.<Message<?>>emptyList(), groupId);
50+
return create(Collections.emptyList(), groupId);
4951
}
5052

5153
@Override
@@ -56,6 +58,7 @@ public MessageGroup create(Collection<? extends Message<?>> messages, Object gro
5658
@Override
5759
public MessageGroup create(Collection<? extends Message<?>> messages, Object groupId, long timestamp,
5860
boolean complete) {
61+
5962
return new SimpleMessageGroup(this.type.get(), messages, groupId, timestamp, complete, false);
6063
}
6164

@@ -72,7 +75,7 @@ public MessageGroup create(MessageGroupStore messageGroupStore, Object groupId)
7275
@Override
7376
public MessageGroup create(MessageGroupStore messageGroupStore, Object groupId, long timestamp, boolean complete) {
7477
if (GroupType.PERSISTENT.equals(this.type)) {
75-
SimpleMessageGroup original = new SimpleMessageGroup(Collections.<Message<?>>emptyList(), groupId,
78+
SimpleMessageGroup original = new SimpleMessageGroup(Collections.emptyList(), groupId,
7679
timestamp, complete);
7780
return new PersistentMessageGroup(messageGroupStore, original);
7881
}
@@ -83,28 +86,44 @@ public MessageGroup create(MessageGroupStore messageGroupStore, Object groupId,
8386

8487
public enum GroupType {
8588

89+
LIST {
90+
91+
@Override
92+
Collection<Message<?>> get() {
93+
return new ArrayList<>();
94+
}
95+
96+
},
97+
8698
BLOCKING_QUEUE {
99+
87100
@Override
88101
Collection<Message<?>> get() {
89-
return new LinkedBlockingQueue<Message<?>>();
102+
return new LinkedBlockingQueue<>();
90103
}
91104

92105
},
106+
93107
HASH_SET {
108+
94109
@Override
95110
Collection<Message<?>> get() {
96-
return new LinkedHashSet<Message<?>>();
111+
return new LinkedHashSet<>();
97112
}
98113

99114
},
115+
100116
SYNCHRONISED_SET {
117+
101118
@Override
102119
Collection<Message<?>> get() {
103120
return Collections.synchronizedSet(new LinkedHashSet<>());
104121
}
105122

106123
},
124+
107125
PERSISTENT {
126+
108127
@Override
109128
Collection<Message<?>> get() {
110129
return HASH_SET.get();

spring-integration-core/src/test/java/org/springframework/integration/aggregator/AggregatorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ public void testAggPerf() throws InterruptedException, ExecutionException, Timeo
102102
SimpleMessageStore store = new SimpleMessageStore();
103103

104104
SimpleMessageGroupFactory messageGroupFactory =
105-
new SimpleMessageGroupFactory(SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE);
105+
new SimpleMessageGroupFactory(SimpleMessageGroupFactory.GroupType.LIST);
106106

107107
store.setMessageGroupFactory(messageGroupFactory);
108108

src/reference/asciidoc/message-store.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ This defaults to a `SimpleMessageGroupFactory` which produces `SimpleMessageGrou
9595
Other possible options are `SYNCHRONISED_SET` and `BLOCKING_QUEUE`, where the last one can be used to reinstate the
9696
previous `SimpleMessageGroup` behavior.
9797
Also the `PERSISTENT` option is available. See the next section for more information.
98+
Starting with __version 5.0.1_, the `LIST` option is also available for use-cases when the order and uniqueness of messages in the group doesn't matter.
9899

99100
[[lazy-load-message-group]]
100101
==== Persistence MessageGroupStore and Lazy-Load

0 commit comments

Comments
 (0)