提交 1fadd1c9 编写于 作者: J Juergen Hoeller

BackOff abstraction lives in util.backoff subpackage now

Issue: SPR-11746
上级 bf9ccc81
......@@ -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;
* <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
......
......@@ -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 {
......
......@@ -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();
......
......@@ -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;
}
}
......
/**
*
* A generic back-off abstraction.
*
*/
package org.springframework.util.backoff;
......@@ -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
......
......@@ -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
*/
......
......@@ -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) {
......
......@@ -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
......
......@@ -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>
......
......@@ -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.*;
/**
*
......
......@@ -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
......
......@@ -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.*;
/**
*
......
......@@ -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>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册