From e90310612f3f8043a1dc91cd4f1cc7f0e4ae7352 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 4 Feb 2016 20:00:00 +0100 Subject: [PATCH] Polishing --- .../util/backoff/ExponentialBackOff.java | 14 ++++++------- .../util/backoff/FixedBackOff.java | 8 ++++---- .../DefaultMessageListenerContainer.java | 20 +++++++++---------- .../AbstractJackson2HttpMessageConverter.java | 7 ++++--- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java index b3bfa9c65df..b7c6efd29cb 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java @@ -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(); diff --git a/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java index 62566f701c6..55c23b5e8a0 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/FixedBackOff.java @@ -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(); } - } } 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 ba55ecc241e..c48c3439df7 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 @@ -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. *

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}. - *

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}. + *

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. *

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). diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java index f844bee510e..b4cc6eda4e0 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java @@ -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; }