INT-3950: Fix Aggregator documentation

JIRA: https://jira.spring.io/browse/INT-3950

Previously there was a mention of the `MessageGroupStore.expireMessageGroup(groupId)` which just doesn't existing
in the Framework and never has been there.

* Fix the documentation for the existing `MessageGroupStore.expireMessageGroups(timeout)`.
Although the mention there of `Control Bus` requires to have `@ManagedOperation` on the method.

* Add `@ManagedOperation` for the `MessageGroupStore.expireMessageGroups(timeout)` and confirm with the test-case: `AggregatorWithMessageStoreParserTests`
* Fix the same docs in the XSD for `<aggregator>`
* Fix other typos in the `aggregator.adoc` and `resequencer.adoc`

Conflicts:
	spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java

Conflicts:
	spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java
	src/reference/asciidoc/aggregator.adoc
	src/reference/asciidoc/resequencer.adoc
This commit is contained in:
Artem Bilan
2016-02-05 11:08:14 -05:00
parent 136dbe40bc
commit afb10bab5e
6 changed files with 25 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
@@ -25,6 +25,7 @@ import org.springframework.integration.support.DefaultMessageBuilderFactory;
import org.springframework.integration.support.MessageBuilderFactory;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.messaging.Message;
@@ -94,11 +95,12 @@ public abstract class AbstractMessageGroupStore implements MessageGroupStore, It
@Override
public void registerMessageGroupExpiryCallback(MessageGroupCallback callback) {
expiryCallbacks.add(callback);
this.expiryCallbacks.add(callback);
}
@Override
public int expireMessageGroups(long timeout) {
@ManagedOperation
public synchronized int expireMessageGroups(long timeout) {
int count = 0;
long threshold = System.currentTimeMillis() - timeout;
for (MessageGroup group : this) {

View File

@@ -15,6 +15,7 @@ package org.springframework.integration.store;
import java.util.Iterator;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.messaging.Message;
/**
@@ -77,6 +78,7 @@ public interface MessageGroupStore extends BasicMessageGroupStore {
*
* @see #registerMessageGroupExpiryCallback(MessageGroupCallback)
*/
@ManagedOperation
int expireMessageGroups(long timeout);
/**
@@ -121,7 +123,7 @@ public interface MessageGroupStore extends BasicMessageGroupStore {
/**
* Invoked when a MessageGroupStore expires a group.
*/
public interface MessageGroupCallback {
interface MessageGroupCallback {
void execute(MessageGroupStore messageGroupStore, MessageGroup group);

View File

@@ -14,10 +14,12 @@
<aggregator id="aggregator" ref="aggregatorBean"
input-channel="input" output-channel="output" message-store="messageStore" send-partial-result-on-expiry="true"/>
<beans:bean id="messageStore" class="org.springframework.integration.store.SimpleMessageStore"/>
<beans:bean id="aggregatorBean"
class="org.springframework.integration.config.TestAggregatorBean" />
<control-bus input-channel="controlBusChannel" output-channel="nullChannel"/>
</beans:beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,31 +26,36 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.store.MessageGroupStore;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dave Syer
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class AggregatorWithMessageStoreParserTests {
@Autowired
@Qualifier("input")
private MessageChannel input;
@Autowired
private TestAggregatorBean aggregatorBean;
@Autowired
private MessageGroupStore messageGroupStore;
@Autowired
private MessageChannel controlBusChannel;
@Test
@DirtiesContext
public void testAggregation() {
input.send(createMessage("123", "id1", 3, 1, null));
assertEquals(1, messageGroupStore.getMessageGroup("id1").size());
input.send(createMessage("789", "id1", 3, 3, null));
@@ -67,12 +72,11 @@ public class AggregatorWithMessageStoreParserTests {
@Test
@DirtiesContext
public void testExpiry() {
input.send(createMessage("123", "id1", 3, 1, null));
assertEquals(1, messageGroupStore.getMessageGroup("id1").size());
input.send(createMessage("456", "id1", 3, 2, null));
assertEquals(2, messageGroupStore.getMessageGroup("id1").size());
messageGroupStore.expireMessageGroups(-10000);
this.controlBusChannel.send(new GenericMessage<Object>("@messageStore.expireMessageGroups(-10000)"));
assertEquals("One and only one message should have been aggregated", 1, aggregatorBean
.getAggregatedMessages().size());
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");

View File

@@ -38,6 +38,7 @@ import org.springframework.integration.store.MessageGroupStore;
import org.springframework.integration.store.MessageStore;
import org.springframework.integration.store.SimpleMessageGroup;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -286,6 +287,7 @@ public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDb
}
@Override
@ManagedOperation
public int expireMessageGroups(long timeout) {
int count = 0;
long threshold = System.currentTimeMillis() - timeout;

View File

@@ -437,7 +437,7 @@ then you should simply provide an implementation of the <classname>ReleaseStrate
once their containing <classname>MessageGroup</classname> is expired (see <code>MessageGroupStore.expireMessageGroups(long)</code>).
One way of expiring <classname>MessageGroup</classname>s is by configuring a <classname>MessageGroupStoreReaper</classname>.
However <classname>MessageGroup</classname>s can alternatively be expired by simply calling
<code>MessageGroupStore.expireMessageGroup(groupId)</code>. That could be accomplished via a Control Bus operation
<code>MessageGroupStore.expireMessageGroups(timeout)</code>. That could be accomplished via a Control Bus operation
or by simply invoking that method if you have a reference to the <classname>MessageGroupStore</classname> instance.
Otherwise by itself this attribute has no behavior. It only serves as an indicator of what to do (discard or send to the output/reply
channel) with Messages that are still in the <classname>MessageGroup</classname> that is about to be expired.