From 960997694ba329bfd6f927f7d42358847b12cc0f Mon Sep 17 00:00:00 2001 From: David Syer Date: Wed, 5 May 2010 11:11:07 +0000 Subject: [PATCH] INT-958: Add explicit setter for callbacks in SimpleMessageStore --- .../integration/store/SimpleMessageStore.java | 12 ++++++++++++ .../integration/store/SimpleMessageStoreTests.java | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java b/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java index 9b3f047dc8..1a560f664a 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/store/SimpleMessageStore.java @@ -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 expiryCallbacks) { + for (MessageGroupCallback callback : expiryCallbacks) { + registerExpiryCallback(callback); + } + } + public Message addMessage(Message message) { if (!upperBound.tryAcquire(0)) { throw new MessagingException(this.getClass().getSimpleName() diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/store/SimpleMessageStoreTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/store/SimpleMessageStoreTests.java index ea4249751e..639758e13e 100644 --- a/org.springframework.integration/src/test/java/org/springframework/integration/store/SimpleMessageStoreTests.java +++ b/org.springframework.integration/src/test/java/org/springframework/integration/store/SimpleMessageStoreTests.java @@ -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.asList(new MessageGroupCallback() { + public void execute(MessageGroup group) { + } + })); + assertEquals(1, ((Collection)ReflectionTestUtils.getField(store, "expiryCallbacks")).size()); + } + @Test public void shouldExpireMessageGroup() throws Exception {