use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class CorrelatingMessageBarrier method receive.
@Override
public Message<Object> receive() {
for (Object key : this.correlationLocks.keySet()) {
Object lock = getLock(key);
synchronized (lock) {
MessageGroup group = this.store.getMessageGroup(key);
// group might be removed by another thread
if (group != null) {
if (this.releaseStrategy.canRelease(group)) {
Message<?> nextMessage = null;
Iterator<Message<?>> messages = group.getMessages().iterator();
if (messages.hasNext()) {
nextMessage = messages.next();
this.store.removeMessagesFromGroup(key, nextMessage);
if (log.isDebugEnabled()) {
log.debug(String.format("Released message for key [%s]: %s.", key, nextMessage));
}
} else {
remove(key);
}
@SuppressWarnings("unchecked") Message<Object> result = (Message<Object>) nextMessage;
return result;
}
}
}
}
return null;
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class MethodInvokingReleaseStrategyTests method testAdapterWithNonParameterizedMessageListBasedMethod.
@Test
public void testAdapterWithNonParameterizedMessageListBasedMethod() {
class TestReleaseStrategy {
@SuppressWarnings("unused")
public boolean checkCompletenessOnNonParameterizedListOfMessages(List<Message<?>> messages) {
Assert.assertTrue(messages.size() > 0);
return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
}
}
ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnNonParameterizedListOfMessages");
MessageGroup messages = createListOfMessages(3);
Assert.assertTrue(adapter.canRelease(messages));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class MethodInvokingReleaseStrategyTests method testAdapterWithPojoBasedMethod.
@Test
public void testAdapterWithPojoBasedMethod() {
class TestReleaseStrategy {
@SuppressWarnings("unused")
public // the data
boolean checkCompletenessOnListOfStrings(List<String> messages) {
StringBuffer buffer = new StringBuffer();
for (String content : messages) {
buffer.append(content);
}
return buffer.length() >= 9;
}
}
ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnListOfStrings");
MessageGroup messages = createListOfMessages(3);
Assert.assertTrue(adapter.canRelease(messages));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testNonExistingEmptyMessageGroup.
@Test
@MongoDbAvailable
public void testNonExistingEmptyMessageGroup() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = getMessageGroupStore();
store.addMessagesToGroup(1, new GenericMessage<Object>("foo"));
MessageGroup messageGroup = store.getMessageGroup(1);
assertNotNull(messageGroup);
assertThat(messageGroup.getClass().getName(), containsString("PersistentMessageGroup"));
assertEquals(1, messageGroup.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader.
@Test
@MongoDbAvailable
public void testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = this.getMessageGroupStore();
MessageStore messageStore = this.getMessageStore();
Object id = UUID.randomUUID();
MessageGroup messageGroup = store.getMessageGroup(id);
UUID uuidA = UUID.randomUUID();
Message<?> messageA = MessageBuilder.withPayload("A").setHeader("foo", uuidA).build();
UUID uuidB = UUID.randomUUID();
Message<?> messageB = MessageBuilder.withPayload("B").setHeader("foo", uuidB).build();
store.addMessagesToGroup(id, messageA);
messageGroup = store.addMessageToGroup(id, messageB);
assertNotNull(messageGroup);
assertEquals(2, messageGroup.size());
Message<?> retrievedMessage = messageStore.getMessage(messageA.getHeaders().getId());
assertNotNull(retrievedMessage);
assertEquals(retrievedMessage.getHeaders().getId(), messageA.getHeaders().getId());
// ensure that 'message_group' header that is only used internally is not propagated
assertNull(retrievedMessage.getHeaders().get("message_group"));
Object fooHeader = retrievedMessage.getHeaders().get("foo");
assertTrue(fooHeader instanceof UUID);
assertEquals(uuidA, fooHeader);
}
Aggregations