Polishing

This commit is contained in:
Juergen Hoeller
2016-02-04 20:00:00 +01:00
parent f108deb114
commit e90310612f
4 changed files with 24 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,6 +103,7 @@ public class ExponentialBackOff implements BackOff {
this.multiplier = multiplier;
}
/**
* The initial interval in milliseconds.
*/
@@ -183,12 +184,12 @@ public class ExponentialBackOff implements BackOff {
@Override
public long nextBackOff() {
if (currentElapsedTime >= maxElapsedTime) {
if (this.currentElapsedTime >= maxElapsedTime) {
return STOP;
}
long nextInterval = computeNextInterval();
currentElapsedTime += nextInterval;
this.currentElapsedTime += nextInterval;
return nextInterval;
}
@@ -205,7 +206,7 @@ public class ExponentialBackOff implements BackOff {
else {
this.currentInterval = multiplyInterval(maxInterval);
}
return currentInterval;
return this.currentInterval;
}
private long multiplyInterval(long maxInterval) {
@@ -217,9 +218,8 @@ public class ExponentialBackOff implements BackOff {
@Override
public String toString() {
String i = (this.currentInterval < 0 ? "n/a" : this.currentInterval + "ms");
final StringBuilder sb = new StringBuilder("ExponentialBackOff{");
sb.append("currentInterval=").append(i);
StringBuilder sb = new StringBuilder("ExponentialBackOff{");
sb.append("currentInterval=").append(this.currentInterval < 0 ? "n/a" : this.currentInterval + "ms");
sb.append(", multiplier=").append(getMultiplier());
sb.append('}');
return sb.toString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,6 +57,7 @@ public class FixedBackOff implements BackOff {
this.maxAttempts = maxAttempts;
}
/**
* Set the interval between two attempts in milliseconds.
*/
@@ -110,14 +111,13 @@ public class FixedBackOff implements BackOff {
public String toString() {
final StringBuilder sb = new StringBuilder("FixedBackOff{");
sb.append("interval=").append(FixedBackOff.this.interval);
String attemptValue = (FixedBackOff.this.maxAttempts == Long.MAX_VALUE ? "unlimited"
: String.valueOf(FixedBackOff.this.maxAttempts));
String attemptValue = (FixedBackOff.this.maxAttempts == Long.MAX_VALUE ?
"unlimited" : String.valueOf(FixedBackOff.this.maxAttempts));
sb.append(", currentAttempts=").append(this.currentAttempts);
sb.append(", maxAttempts=").append(attemptValue);
sb.append('}');
return sb.toString();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -175,7 +175,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
private Executor taskExecutor;
private BackOff backOff = createDefaultBackOff(DEFAULT_RECOVERY_INTERVAL);
private BackOff backOff = new FixedBackOff(DEFAULT_RECOVERY_INTERVAL, Long.MAX_VALUE);
private int cacheLevel = CACHE_AUTO;
@@ -229,6 +229,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
* attempt to recover.
* <p>The {@link #setRecoveryInterval(long) recovery interval} is ignored
* when this property is set.
* @since 4.1
*/
public void setBackOff(BackOff backOff) {
this.backOff = backOff;
@@ -244,7 +245,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
* @see #handleListenerSetupFailure
*/
public void setRecoveryInterval(long recoveryInterval) {
this.backOff = createDefaultBackOff(recoveryInterval);
this.backOff = new FixedBackOff(recoveryInterval, Long.MAX_VALUE);
}
/**
@@ -941,7 +942,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
StringBuilder msg = new StringBuilder();
msg.append("Stopping container for destination '")
.append(getDestinationDescription())
.append("' - back off policy does not allow ").append("for further attempts.");
.append("': back-off policy does not allow ").append("for further attempts.");
logger.error(msg.toString());
stop();
}
@@ -968,10 +969,11 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
}
/**
* Apply the next back off time using the specified {@link BackOffExecution}.
* <p>Return {@code true} if the back off period has been applied and a new
* Apply the next back-off time using the specified {@link BackOffExecution}.
* <p>Return {@code true} if the back-off period has been applied and a new
* attempt to recover should be made, {@code false} if no further attempt
* should be made.
* @since 4.1
*/
protected boolean applyBackOffTime(BackOffExecution execution) {
long interval = execution.nextBackOff();
@@ -990,10 +992,6 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
return true;
}
private FixedBackOff createDefaultBackOff(long interval) {
return new FixedBackOff(interval, Long.MAX_VALUE);
}
/**
* Return whether this listener container is currently in a recovery attempt.
* <p>May be used to detect recovery phases but also the end of a recovery phase,
@@ -1205,7 +1203,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
}
/**
* Apply the back off time once. In a regular scenario, the back off is only applied if we
* Apply the back-off time once. In a regular scenario, the back-off is only applied if we
* failed to recover with the broker. This additional sleep period avoids a burst retry
* scenario when the broker is actually up but something else if failing (i.e. listener
* specific).

View File

@@ -301,7 +301,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
protected JavaType getJavaType(Type type, Class<?> contextClass) {
TypeFactory typeFactory = this.objectMapper.getTypeFactory();
if (type instanceof TypeVariable && contextClass != null) {
ResolvableType resolvedType = resolveVariable((TypeVariable<?>)type, ResolvableType.forClass(contextClass));
ResolvableType resolvedType = resolveVariable(
(TypeVariable<?>) type, ResolvableType.forClass(contextClass));
if (resolvedType != ResolvableType.NONE) {
return typeFactory.constructType(resolvedType.resolve());
}
@@ -321,8 +322,8 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
if (resolvedType.resolve() != null) {
return resolvedType;
}
for (ResolvableType i : contextType.getInterfaces()) {
resolvedType = resolveVariable(typeVariable, i);
for (ResolvableType ifc : contextType.getInterfaces()) {
resolvedType = resolveVariable(typeVariable, ifc);
if (resolvedType.resolve() != null) {
return resolvedType;
}