List of usage examples for org.springframework.integration.store MessageGroup isComplete
boolean isComplete();
From source file:org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.java
@Override protected void handleMessageInternal(Message<?> message) throws Exception { Object correlationKey = correlationStrategy.getCorrelationKey(message); Assert.state(correlationKey != null, "Null correlation not allowed. Maybe the CorrelationStrategy is failing?"); if (logger.isDebugEnabled()) { logger.debug("Handling message with correlationKey [" + correlationKey + "]: " + message); }/* w w w .j a v a2 s.c o m*/ // TODO: INT-1117 - make the lock global? Lock lock = this.lockRegistry.obtain(UUIDConverter.getUUID(correlationKey).toString()); lock.lockInterruptibly(); try { MessageGroup messageGroup = messageStore.getMessageGroup(correlationKey); if (this.sequenceAware) { messageGroup = new SequenceAwareMessageGroup(messageGroup); } if (!messageGroup.isComplete() && messageGroup.canAdd(message)) { if (logger.isTraceEnabled()) { logger.trace("Adding message to group [ " + messageGroup + "]"); } messageGroup = this.store(correlationKey, message); if (releaseStrategy.canRelease(messageGroup)) { Collection<Message<?>> completedMessages = null; try { completedMessages = this.completeGroup(message, correlationKey, messageGroup); } finally { // Always clean up even if there was an exception // processing messages this.afterRelease(messageGroup, completedMessages); } } } else { discardChannel.send(message); } } finally { lock.unlock(); } }
From source file:org.springframework.integration.aggregator.CorrelatingMessageHandler.java
@Override protected void handleMessageInternal(Message<?> message) throws Exception { Object correlationKey = correlationStrategy.getCorrelationKey(message); Assert.state(correlationKey != null, "Null correlation not allowed. Maybe the CorrelationStrategy is failing?"); if (logger.isDebugEnabled()) { logger.debug("Handling message with correlationKey [" + correlationKey + "]: " + message); }//from w w w . jav a 2s . co m // TODO: INT-1117 - make the lock global? Object lock = getLock(correlationKey); synchronized (lock) { MessageGroup group = messageStore.getMessageGroup(correlationKey); if (group.canAdd(message)) { group = store(correlationKey, message); if (releaseStrategy.canRelease(group)) { Collection<Message> completedMessages = null; try { completedMessages = completeGroup(message, correlationKey, group); } finally { // Always clean up even if there was an exception // processing messages cleanUpForReleasedGroup(group, completedMessages); } } else if (group.isComplete()) { try { // If not releasing any messages the group might still // be complete for (Message<?> discard : group.getUnmarked()) { discardChannel.send(discard); } } finally { remove(group); } } } else { discardChannel.send(message); } } }
From source file:org.springframework.integration.aggregator.CorrelatingMessageHandler.java
private void cleanUpForReleasedGroup(MessageGroup group, Collection<Message> completedMessages) { if (group.isComplete() || group.getSequenceSize() == 0) { // The group is complete or else there is no // sequence so there is no more state to track remove(group);//from w w w. j av a2 s .co m } else { // Mark these messages as processed, but do not // remove the group from store if (completedMessages == null) { mark(group); } else { mark(group, completedMessages); } } }
From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java
@Test @Transactional//from w ww . j av a 2s .c o m public void testCompleteMessageGroup() throws Exception { String groupId = "X"; Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build(); messageStore.addMessageToGroup(groupId, message); messageStore.completeGroup(groupId); MessageGroup group = messageStore.getMessageGroup(groupId); assertTrue(group.isComplete()); assertEquals(1, group.size()); }
From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java
@Test @Transactional/*w w w .j a va2 s .co m*/ public void testCompletedNotExpiredGroupINT3037() throws Exception { /* * based on the aggregator scenario as follows; * * send three messages in * 1 of 2 * 2 of 2 * 2 of 2 (last again) * * expected behavior is that the LAST message (2 of 2 repeat) should be on the discard channel * (discard behavior performed by the AbstractCorrelatingMessageHandler.handleMessageInternal) */ final JdbcMessageStore messageStore = new JdbcMessageStore(dataSource); //init String groupId = "group"; //build the messages Message<?> oneOfTwo = MessageBuilder.withPayload("hello").setSequenceNumber(1).setSequenceSize(2) .setCorrelationId(groupId).build(); Message<?> twoOfTwo = MessageBuilder.withPayload("world").setSequenceNumber(2).setSequenceSize(2) .setCorrelationId(groupId).build(); //add to the messageStore messageStore.addMessageToGroup(groupId, oneOfTwo); messageStore.addMessageToGroup(groupId, twoOfTwo); //check that 2 messages are there assertTrue(messageStore.getMessageGroupCount() == 1); assertTrue(messageStore.getMessageCount() == 2); //retrieve the group (like in the aggregator) MessageGroup messageGroup = messageStore.getMessageGroup(groupId); //'complete' the group messageStore.completeGroup(messageGroup.getGroupId()); //now clear the messages for (Message<?> message : messageGroup.getMessages()) { messageStore.removeMessageFromGroup(groupId, message); } //end for //'add' the other message --> emulated by getting the messageGroup messageGroup = messageStore.getMessageGroup(groupId); //should be marked 'complete' --> old behavior it would not assertTrue(messageGroup.isComplete()); }