From 1fadd1c954510e924dab1c0a6c34330091672519 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 9 Jul 2014 21:53:32 +0200 Subject: [PATCH] BackOff abstraction lives in util.backoff subpackage now Issue: SPR-11746 --- .../util/{ => backoff}/BackOff.java | 30 +++++++++---------- .../util/{ => backoff}/BackOffExecution.java | 4 +-- .../{ => backoff}/ExponentialBackOff.java | 4 +-- .../util/{ => backoff}/FixedBackOff.java | 4 +-- .../util/backoff/package-info.java | 8 +++++ .../util/ExponentialBackOffTests.java | 3 ++ .../util/FixedBackOffTests.java | 3 ++ .../DefaultJmsListenerContainerFactory.java | 24 ++++++++------- .../DefaultMessageListenerContainer.java | 6 ++-- .../jms/config/spring-jms-4.1.xsd | 2 +- .../JmsListenerContainerFactoryTests.java | 10 +++---- .../jms/config/JmsNamespaceHandlerTests.java | 11 ++++--- .../DefaultMessageListenerContainerTests.java | 10 +++---- .../jms/config/jmsNamespaceHandlerTests.xml | 2 +- 14 files changed, 67 insertions(+), 54 deletions(-) rename spring-core/src/main/java/org/springframework/util/{ => backoff}/BackOff.java (69%) rename spring-core/src/main/java/org/springframework/util/{ => backoff}/BackOffExecution.java (93%) rename spring-core/src/main/java/org/springframework/util/{ => backoff}/ExponentialBackOff.java (98%) rename spring-core/src/main/java/org/springframework/util/{ => backoff}/FixedBackOff.java (97%) create mode 100644 spring-core/src/main/java/org/springframework/util/backoff/package-info.java diff --git a/spring-core/src/main/java/org/springframework/util/BackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/BackOff.java similarity index 69% rename from spring-core/src/main/java/org/springframework/util/BackOff.java rename to spring-core/src/main/java/org/springframework/util/backoff/BackOff.java index 01c43932ae..0543ac917a 100644 --- a/spring-core/src/main/java/org/springframework/util/BackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/BackOff.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.util; +package org.springframework.util.backoff; /** * Provide a {@link BackOffExecution} that indicates the rate at which @@ -23,23 +23,21 @@ package org.springframework.util; *

Users of this interface are expected to use it like this: * *

- * {@code
- *
- *  BackOffExecution exec = backOff.start();
- *
- *  // In the operation recovery/retry loop:
- *  long waitInterval = exec.nextBackOffMillis();
- *  if (waitInterval == BackOffExecution.STOP) {
- *    // do not retry operation
- *  }
- *  else {
- *    // sleep, e.g. Thread.sleep(waitInterval)
- *    // retry operation
- *  }
+ * BackOffExecution exec = backOff.start();
+ *
+ * // In the operation recovery/retry loop:
+ * long waitInterval = exec.nextBackOffMillis();
+ * if (waitInterval == BackOffExecution.STOP) {
+ *     // do not retry operation
+ * }
+ * else {
+ *     // sleep, e.g. Thread.sleep(waitInterval)
+ *     // retry operation
+ * }
  * }
* - * Once the underlying operation has completed successfully, the execution - * instance can be simply discarded. + * Once the underlying operation has completed successfully, + * the execution instance can be simply discarded. * * @author Stephane Nicoll * @since 4.1 diff --git a/spring-core/src/main/java/org/springframework/util/BackOffExecution.java b/spring-core/src/main/java/org/springframework/util/backoff/BackOffExecution.java similarity index 93% rename from spring-core/src/main/java/org/springframework/util/BackOffExecution.java rename to spring-core/src/main/java/org/springframework/util/backoff/BackOffExecution.java index d5a45fa556..4204285ceb 100644 --- a/spring-core/src/main/java/org/springframework/util/BackOffExecution.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/BackOffExecution.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.util; +package org.springframework.util.backoff; /** * Represent a particular back-off execution. @@ -23,7 +23,7 @@ package org.springframework.util; * * @author Stephane Nicoll * @since 4.1 - * @see org.springframework.util.BackOff + * @see BackOff */ public interface BackOffExecution { diff --git a/spring-core/src/main/java/org/springframework/util/ExponentialBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java similarity index 98% rename from spring-core/src/main/java/org/springframework/util/ExponentialBackOff.java rename to spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java index 3e0f533eda..005d787d1b 100644 --- a/spring-core/src/main/java/org/springframework/util/ExponentialBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.util; +package org.springframework.util.backoff; /** * Implementation of {@link BackOff} that increases the back off period for each @@ -184,7 +184,7 @@ public class ExponentialBackOff implements BackOff { @Override public long nextBackOff() { if (currentElapsedTime >= maxElapsedTime) { - return BackOffExecution.STOP; + return STOP; } long nextInterval = computeNextInterval(); diff --git a/spring-core/src/main/java/org/springframework/util/FixedBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java similarity index 97% rename from spring-core/src/main/java/org/springframework/util/FixedBackOff.java rename to spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java index c32f12b7b3..ec88d8d097 100644 --- a/spring-core/src/main/java/org/springframework/util/FixedBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.util; +package org.springframework.util.backoff; /** * A simple {@link BackOff} implementation that provides a fixed interval @@ -102,7 +102,7 @@ public class FixedBackOff implements BackOff { return getInterval(); } else { - return BackOffExecution.STOP; + return STOP; } } diff --git a/spring-core/src/main/java/org/springframework/util/backoff/package-info.java b/spring-core/src/main/java/org/springframework/util/backoff/package-info.java new file mode 100644 index 0000000000..e06d4b52a0 --- /dev/null +++ b/spring-core/src/main/java/org/springframework/util/backoff/package-info.java @@ -0,0 +1,8 @@ + +/** + * + * A generic back-off abstraction. + * + */ +package org.springframework.util.backoff; + diff --git a/spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java b/spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java index 6fbfc8fde7..b2a7c61c4b 100644 --- a/spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java +++ b/spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java @@ -22,6 +22,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.springframework.util.backoff.BackOffExecution; +import org.springframework.util.backoff.ExponentialBackOff; + /** * * @author Stephane Nicoll diff --git a/spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java b/spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java index 3359fc925b..1e85c687d1 100644 --- a/spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java +++ b/spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java @@ -20,6 +20,9 @@ import static org.junit.Assert.*; import org.junit.Test; +import org.springframework.util.backoff.BackOffExecution; +import org.springframework.util.backoff.FixedBackOff; + /** * @author Stephane Nicoll */ diff --git a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java index b611d17976..7118f88feb 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java @@ -20,7 +20,7 @@ import java.util.concurrent.Executor; import org.springframework.jms.listener.DefaultMessageListenerContainer; import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.util.BackOff; +import org.springframework.util.backoff.BackOff; /** * A {@link JmsListenerContainerFactory} implementation to build regular @@ -54,69 +54,71 @@ public class DefaultJmsListenerContainerFactory private BackOff backOff; + /** - * @see DefaultMessageListenerContainer#setTaskExecutor(java.util.concurrent.Executor) + * @see DefaultMessageListenerContainer#setTaskExecutor */ public void setTaskExecutor(Executor taskExecutor) { this.taskExecutor = taskExecutor; } /** - * @see DefaultMessageListenerContainer#setTransactionManager(PlatformTransactionManager) + * @see DefaultMessageListenerContainer#setTransactionManager */ public void setTransactionManager(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } /** - * @see DefaultMessageListenerContainer#setCacheLevel(int) + * @see DefaultMessageListenerContainer#setCacheLevel */ public void setCacheLevel(Integer cacheLevel) { this.cacheLevel = cacheLevel; } /** - * @see DefaultMessageListenerContainer#setCacheLevelName(String) + * @see DefaultMessageListenerContainer#setCacheLevelName */ public void setCacheLevelName(String cacheLevelName) { this.cacheLevelName = cacheLevelName; } /** - * @see DefaultMessageListenerContainer#setConcurrency(String) + * @see DefaultMessageListenerContainer#setConcurrency */ public void setConcurrency(String concurrency) { this.concurrency = concurrency; } /** - * @see DefaultMessageListenerContainer#setMaxMessagesPerTask(int) + * @see DefaultMessageListenerContainer#setMaxMessagesPerTask */ public void setMaxMessagesPerTask(Integer maxMessagesPerTask) { this.maxMessagesPerTask = maxMessagesPerTask; } /** - * @see DefaultMessageListenerContainer#setReceiveTimeout(long) + * @see DefaultMessageListenerContainer#setReceiveTimeout */ public void setReceiveTimeout(Long receiveTimeout) { this.receiveTimeout = receiveTimeout; } /** - * @see DefaultMessageListenerContainer#setRecoveryInterval(long) + * @see DefaultMessageListenerContainer#setRecoveryInterval */ public void setRecoveryInterval(Long recoveryInterval) { this.recoveryInterval = recoveryInterval; } /** - * @see DefaultMessageListenerContainer#setBackOff(BackOff) + * @see DefaultMessageListenerContainer#setBackOff */ public void setBackOff(BackOff backOff) { this.backOff = backOff; } + @Override protected DefaultMessageListenerContainer createContainerInstance() { return new DefaultMessageListenerContainer(); @@ -151,7 +153,7 @@ public class DefaultJmsListenerContainerFactory if (this.backOff != null) { container.setBackOff(this.backOff); if (this.recoveryInterval != null) { - logger.warn("Ignoring recovery interval value as a BackOff instance is set."); + logger.warn("Ignoring recovery interval in DefaultJmsListenerContainerFactory in favor of BackOff"); } } else if (this.recoveryInterval != null) { diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java index abc4d99113..4c942f512e 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java @@ -34,10 +34,10 @@ import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.util.Assert; -import org.springframework.util.BackOff; -import org.springframework.util.BackOffExecution; import org.springframework.util.ClassUtils; -import org.springframework.util.FixedBackOff; +import org.springframework.util.backoff.BackOff; +import org.springframework.util.backoff.BackOffExecution; +import org.springframework.util.backoff.FixedBackOff; /** * Message listener container variant that uses plain JMS client APIs, specifically diff --git a/spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd b/spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd index 38262d44bc..6df309c198 100644 --- a/spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd +++ b/spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd @@ -329,7 +329,7 @@ ]]> - + diff --git a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java index 1c645ba8ad..2e63fba4e7 100644 --- a/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java @@ -16,9 +16,6 @@ package org.springframework.jms.config; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - import javax.jms.ConnectionFactory; import javax.jms.MessageListener; import javax.jms.Session; @@ -41,8 +38,11 @@ import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.SimpleMessageConverter; import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.jms.support.destination.DynamicDestinationResolver; -import org.springframework.util.BackOff; -import org.springframework.util.FixedBackOff; +import org.springframework.util.backoff.BackOff; +import org.springframework.util.backoff.FixedBackOff; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; /** * diff --git a/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java b/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java index 66517166d9..d14169883c 100644 --- a/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java @@ -16,14 +16,10 @@ package org.springframework.jms.config; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; - import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; - import javax.jms.ConnectionFactory; import javax.jms.Message; import javax.jms.MessageListener; @@ -48,9 +44,12 @@ import org.springframework.jms.listener.DefaultMessageListenerContainer; import org.springframework.jms.listener.adapter.MessageListenerAdapter; import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager; import org.springframework.tests.sample.beans.TestBean; -import org.springframework.util.BackOff; import org.springframework.util.ErrorHandler; -import org.springframework.util.FixedBackOff; +import org.springframework.util.backoff.BackOff; +import org.springframework.util.backoff.FixedBackOff; + +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; /** * @author Mark Fisher diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java index 2746f5c9fc..792de56fc2 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java @@ -16,9 +16,6 @@ package org.springframework.jms.listener; -import static org.junit.Assert.*; -import static org.mockito.BDDMockito.*; - import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; @@ -28,8 +25,11 @@ import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.springframework.util.BackOff; -import org.springframework.util.BackOffExecution; +import org.springframework.util.backoff.BackOff; +import org.springframework.util.backoff.BackOffExecution; + +import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; /** * diff --git a/spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml b/spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml index 2905a33d3e..e5bad55eb4 100644 --- a/spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml +++ b/spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml @@ -68,7 +68,7 @@ - +