INT-958: Add explicit setter for callbacks in SimpleMessageStore

This commit is contained in:
David Syer
2010-05-05 11:11:07 +00:00
parent 9b6d5720f8
commit 960997694b
2 changed files with 25 additions and 0 deletions

View File

@@ -65,6 +65,18 @@ public class SimpleMessageStore implements MessageStore, MessageGroupStore {
this(0);
}
/**
* Convenient injection point for expiry callbacks in the message store. Each of the callbacks provided will simply
* be registered with the store using {@link #registerExpiryCallback(MessageGroupCallback)}.
*
* @param expiryCallbacks the expiry callbacks to add
*/
public void setExpiryCallbacks(Collection<MessageGroupCallback> expiryCallbacks) {
for (MessageGroupCallback callback : expiryCallbacks) {
registerExpiryCallback(callback);
}
}
public <T> Message<T> addMessage(Message<T> message) {
if (!upperBound.tryAcquire(0)) {
throw new MessagingException(this.getClass().getSimpleName()

View File

@@ -22,12 +22,15 @@ import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessagingException;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.test.util.ReflectionTestUtils;
/**
* @author Iwein Fuld
@@ -78,6 +81,16 @@ public class SimpleMessageStoreTests {
assertNotSame(store.getMessageGroup("bar"), store.getMessageGroup("bar"));
}
@Test
public void shouldRegisterCallbacks() throws Exception {
SimpleMessageStore store = new SimpleMessageStore();
store.setExpiryCallbacks(Arrays.<MessageGroupCallback>asList(new MessageGroupCallback() {
public void execute(MessageGroup group) {
}
}));
assertEquals(1, ((Collection<?>)ReflectionTestUtils.getField(store, "expiryCallbacks")).size());
}
@Test
public void shouldExpireMessageGroup() throws Exception {