Browse Source

BackOff abstraction lives in util.backoff subpackage now

Issue: SPR-11746
pull/589/head
Juergen Hoeller 11 years ago
parent
commit
1fadd1c954
  1. 30
      spring-core/src/main/java/org/springframework/util/backoff/BackOff.java
  2. 4
      spring-core/src/main/java/org/springframework/util/backoff/BackOffExecution.java
  3. 4
      spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java
  4. 4
      spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java
  5. 8
      spring-core/src/main/java/org/springframework/util/backoff/package-info.java
  6. 3
      spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java
  7. 3
      spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java
  8. 24
      spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java
  9. 6
      spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java
  10. 2
      spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd
  11. 10
      spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java
  12. 11
      spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java
  13. 10
      spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java
  14. 2
      spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml

30
spring-core/src/main/java/org/springframework/util/BackOff.java → spring-core/src/main/java/org/springframework/util/backoff/BackOff.java

@ -14,7 +14,7 @@ @@ -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; @@ -23,23 +23,21 @@ package org.springframework.util;
* <p>Users of this interface are expected to use it like this:
*
* <pre class="code">
* {@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
* }
* }</pre>
*
* 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

4
spring-core/src/main/java/org/springframework/util/BackOffExecution.java → spring-core/src/main/java/org/springframework/util/backoff/BackOffExecution.java

@ -14,7 +14,7 @@ @@ -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; @@ -23,7 +23,7 @@ package org.springframework.util;
*
* @author Stephane Nicoll
* @since 4.1
* @see org.springframework.util.BackOff
* @see BackOff
*/
public interface BackOffExecution {

4
spring-core/src/main/java/org/springframework/util/ExponentialBackOff.java → spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java

@ -14,7 +14,7 @@ @@ -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 { @@ -184,7 +184,7 @@ public class ExponentialBackOff implements BackOff {
@Override
public long nextBackOff() {
if (currentElapsedTime >= maxElapsedTime) {
return BackOffExecution.STOP;
return STOP;
}
long nextInterval = computeNextInterval();

4
spring-core/src/main/java/org/springframework/util/FixedBackOff.java → spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java

@ -14,7 +14,7 @@ @@ -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 { @@ -102,7 +102,7 @@ public class FixedBackOff implements BackOff {
return getInterval();
}
else {
return BackOffExecution.STOP;
return STOP;
}
}

8
spring-core/src/main/java/org/springframework/util/backoff/package-info.java

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
/**
*
* A generic back-off abstraction.
*
*/
package org.springframework.util.backoff;

3
spring-core/src/test/java/org/springframework/util/ExponentialBackOffTests.java

@ -22,6 +22,9 @@ import org.junit.Rule; @@ -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

3
spring-core/src/test/java/org/springframework/util/FixedBackOffTests.java

@ -20,6 +20,9 @@ import static org.junit.Assert.*; @@ -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
*/

24
spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java

@ -20,7 +20,7 @@ import java.util.concurrent.Executor; @@ -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 @@ -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 @@ -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) {

6
spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java

@ -34,10 +34,10 @@ import org.springframework.jms.support.destination.DestinationResolver; @@ -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

2
spring-jms/src/main/resources/org/springframework/jms/config/spring-jms-4.1.xsd

@ -329,7 +329,7 @@ @@ -329,7 +329,7 @@
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.util.BackOff"/>
<tool:expected-type type="org.springframework.util.backoff.BackOff"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>

10
spring-jms/src/test/java/org/springframework/jms/config/JmsListenerContainerFactoryTests.java

@ -16,9 +16,6 @@ @@ -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; @@ -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.*;
/**
*

11
spring-jms/src/test/java/org/springframework/jms/config/JmsNamespaceHandlerTests.java

@ -16,14 +16,10 @@ @@ -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; @@ -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

10
spring-jms/src/test/java/org/springframework/jms/listener/DefaultMessageListenerContainerTests.java

@ -16,9 +16,6 @@ @@ -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; @@ -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.*;
/**
*

2
spring-jms/src/test/resources/org/springframework/jms/config/jmsNamespaceHandlerTests.xml

@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
<bean id="testErrorHandler" class="org.springframework.jms.config.JmsNamespaceHandlerTests$TestErrorHandler"/>
<bean id="testBackOff" class="org.springframework.util.FixedBackOff">
<bean id="testBackOff" class="org.springframework.util.backoff.FixedBackOff">
<property name="interval" value="1000"/>
</bean>

Loading…
Cancel
Save