Commit 64c5e8b6 authored by Phillip Webb's avatar Phillip Webb

Rename @DurationUnit -> @DefaultDurationUnit

Rename `@DurationUnit` to `@DefaultDurationUnit` to make it clearer
that it only changes the unit if one isn't specified by the user.

Closes gh-11078
parent 6f3ca459
...@@ -22,7 +22,7 @@ import java.util.ArrayList; ...@@ -22,7 +22,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
/** /**
* Configuration properties for MVC endpoints' CORS support. * Configuration properties for MVC endpoints' CORS support.
...@@ -64,7 +64,7 @@ public class CorsEndpointProperties { ...@@ -64,7 +64,7 @@ public class CorsEndpointProperties {
* How long the response from a pre-flight request can be cached by clients. If a * How long the response from a pre-flight request can be cached by clients. If a
* duration suffix is not specified, seconds will be used. * duration suffix is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration maxAge = Duration.ofSeconds(1800); private Duration maxAge = Duration.ofSeconds(1800);
public List<String> getAllowedOrigins() { public List<String> getAllowedOrigins() {
......
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -80,7 +80,7 @@ public class RabbitProperties { ...@@ -80,7 +80,7 @@ public class RabbitProperties {
* Requested heartbeat timeout; zero for none. If a duration suffix is not specified, * Requested heartbeat timeout; zero for none. If a duration suffix is not specified,
* seconds will be used. * seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration requestedHeartbeat; private Duration requestedHeartbeat;
/** /**
......
...@@ -28,7 +28,7 @@ import com.datastax.driver.core.policies.ReconnectionPolicy; ...@@ -28,7 +28,7 @@ import com.datastax.driver.core.policies.ReconnectionPolicy;
import com.datastax.driver.core.policies.RetryPolicy; import com.datastax.driver.core.policies.RetryPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
/** /**
* Configuration properties for Cassandra. * Configuration properties for Cassandra.
...@@ -283,7 +283,7 @@ public class CassandraProperties { ...@@ -283,7 +283,7 @@ public class CassandraProperties {
* Idle timeout before an idle connection is removed. If a duration suffix is not * Idle timeout before an idle connection is removed. If a duration suffix is not
* specified, seconds will be used. * specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration idleTimeout = Duration.ofSeconds(120); private Duration idleTimeout = Duration.ofSeconds(120);
/** /**
...@@ -296,7 +296,7 @@ public class CassandraProperties { ...@@ -296,7 +296,7 @@ public class CassandraProperties {
* sure it's still alive. If a duration suffix is not specified, seconds will be * sure it's still alive. If a duration suffix is not specified, seconds will be
* used. * used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration heartbeatInterval = Duration.ofSeconds(30); private Duration heartbeatInterval = Duration.ofSeconds(30);
/** /**
......
...@@ -20,7 +20,7 @@ import java.time.Duration; ...@@ -20,7 +20,7 @@ import java.time.Duration;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
/** /**
* Configuration properties for JDBC. * Configuration properties for JDBC.
...@@ -58,7 +58,7 @@ public class JdbcProperties { ...@@ -58,7 +58,7 @@ public class JdbcProperties {
* Query timeout. Default is to use the JDBC driver's default configuration. If a * Query timeout. Default is to use the JDBC driver's default configuration. If a
* duration suffix is not specified, seconds will be used. * duration suffix is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration queryTimeout; private Duration queryTimeout;
public int getFetchSize() { public int getFetchSize() {
......
...@@ -20,7 +20,7 @@ import java.time.Duration; ...@@ -20,7 +20,7 @@ import java.time.Duration;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.transaction.support.AbstractPlatformTransactionManager; import org.springframework.transaction.support.AbstractPlatformTransactionManager;
/** /**
...@@ -39,7 +39,7 @@ public class TransactionProperties implements ...@@ -39,7 +39,7 @@ public class TransactionProperties implements
* Default transaction timeout. If a duration suffix is not specified, seconds will be * Default transaction timeout. If a duration suffix is not specified, seconds will be
* used. * used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration defaultTimeout; private Duration defaultTimeout;
/** /**
......
...@@ -21,7 +21,7 @@ import java.time.temporal.ChronoUnit; ...@@ -21,7 +21,7 @@ import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.http.CacheControl; import org.springframework.http.CacheControl;
/** /**
...@@ -52,7 +52,7 @@ public class ResourceProperties { ...@@ -52,7 +52,7 @@ public class ResourceProperties {
* If a duration suffix is not specified, seconds will be used. * If a duration suffix is not specified, seconds will be used.
* Can be overridden by the {@code cache-control} property. * Can be overridden by the {@code cache-control} property.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration cachePeriod; private Duration cachePeriod;
/** /**
...@@ -300,7 +300,7 @@ public class ResourceProperties { ...@@ -300,7 +300,7 @@ public class ResourceProperties {
* Maximum time the response should be cached, * Maximum time the response should be cached,
* in seconds if no duration suffix is not specified. * in seconds if no duration suffix is not specified.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration maxAge; private Duration maxAge;
/** /**
...@@ -347,21 +347,21 @@ public class ResourceProperties { ...@@ -347,21 +347,21 @@ public class ResourceProperties {
* Maximum time the response can be served after it becomes stale, * Maximum time the response can be served after it becomes stale,
* in seconds if no duration suffix is not specified. * in seconds if no duration suffix is not specified.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration staleWhileRevalidate; private Duration staleWhileRevalidate;
/** /**
* Maximum time the response may be used when errors are encountered, * Maximum time the response may be used when errors are encountered,
* in seconds if no duration suffix is not specified. * in seconds if no duration suffix is not specified.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration staleIfError; private Duration staleIfError;
/** /**
* Maximum time the response should be cached by shared caches, * Maximum time the response should be cached by shared caches,
* in seconds if no duration suffix is not specified. * in seconds if no duration suffix is not specified.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration sMaxAge; private Duration sMaxAge;
public Duration getMaxAge() { public Duration getMaxAge() {
......
...@@ -32,7 +32,7 @@ import java.util.TimeZone; ...@@ -32,7 +32,7 @@ import java.util.TimeZone;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.web.server.Compression; import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2; import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl;
...@@ -340,7 +340,7 @@ public class ServerProperties { ...@@ -340,7 +340,7 @@ public class ServerProperties {
/** /**
* Session timeout. If a duration suffix is not specified, seconds will be used. * Session timeout. If a duration suffix is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration timeout; private Duration timeout;
/** /**
...@@ -434,7 +434,7 @@ public class ServerProperties { ...@@ -434,7 +434,7 @@ public class ServerProperties {
/** /**
* Maximum age of the session cookie. * Maximum age of the session cookie.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration maxAge; private Duration maxAge;
public String getName() { public String getName() {
...@@ -570,7 +570,7 @@ public class ServerProperties { ...@@ -570,7 +570,7 @@ public class ServerProperties {
* Delay between the invocation of backgroundProcess methods. If a duration suffix * Delay between the invocation of backgroundProcess methods. If a duration suffix
* is not specified, seconds will be used. * is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration backgroundProcessorDelay = Duration.ofSeconds(30); private Duration backgroundProcessorDelay = Duration.ofSeconds(30);
/** /**
......
...@@ -34,7 +34,7 @@ import java.time.temporal.ChronoUnit; ...@@ -34,7 +34,7 @@ import java.time.temporal.ChronoUnit;
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
public @interface DurationUnit { public @interface DefaultDurationUnit {
/** /**
* The duration unit to use if one is not specified. * The duration unit to use if one is not specified.
......
...@@ -77,10 +77,10 @@ class DurationConverter implements GenericConverter { ...@@ -77,10 +77,10 @@ class DurationConverter implements GenericConverter {
return null; return null;
} }
return toDuration(source.toString(), return toDuration(source.toString(),
targetType.getAnnotation(DurationUnit.class)); targetType.getAnnotation(DefaultDurationUnit.class));
} }
private Duration toDuration(String source, DurationUnit defaultUnit) { private Duration toDuration(String source, DefaultDurationUnit defaultUnit) {
try { try {
if (!StringUtils.hasLength(source)) { if (!StringUtils.hasLength(source)) {
return null; return null;
...@@ -100,7 +100,7 @@ class DurationConverter implements GenericConverter { ...@@ -100,7 +100,7 @@ class DurationConverter implements GenericConverter {
} }
} }
private ChronoUnit getUnit(String value, DurationUnit defaultUnit) { private ChronoUnit getUnit(String value, DefaultDurationUnit defaultUnit) {
if (StringUtils.isEmpty(value)) { if (StringUtils.isEmpty(value)) {
return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS); return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS);
} }
......
...@@ -24,7 +24,7 @@ import java.util.Collections; ...@@ -24,7 +24,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DurationUnit; import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
/** /**
* Subset of Narayana properties which can be configured via Spring configuration. Use * Subset of Narayana properties which can be configured via Spring configuration. Use
...@@ -59,21 +59,21 @@ public class NarayanaProperties { ...@@ -59,21 +59,21 @@ public class NarayanaProperties {
/** /**
* Transaction timeout. If a duration suffix is not specified, seconds will be used. * Transaction timeout. If a duration suffix is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration defaultTimeout = Duration.ofSeconds(60); private Duration defaultTimeout = Duration.ofSeconds(60);
/** /**
* Interval in which periodic recovery scans are performed. If a duration suffix is * Interval in which periodic recovery scans are performed. If a duration suffix is
* not specified, seconds will be used. * not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration periodicRecoveryPeriod = Duration.ofSeconds(120); private Duration periodicRecoveryPeriod = Duration.ofSeconds(120);
/** /**
* Back off period between first and second phases of the recovery scan. If a duration * Back off period between first and second phases of the recovery scan. If a duration
* suffix is not specified, seconds will be used. * suffix is not specified, seconds will be used.
*/ */
@DurationUnit(ChronoUnit.SECONDS) @DefaultDurationUnit(ChronoUnit.SECONDS)
private Duration recoveryBackoffPeriod = Duration.ofSeconds(10); private Duration recoveryBackoffPeriod = Duration.ofSeconds(10);
/** /**
......
...@@ -138,9 +138,9 @@ public class DurationConverterTests { ...@@ -138,9 +138,9 @@ public class DurationConverterTests {
private Duration convert(String source, ChronoUnit defaultUnit) { private Duration convert(String source, ChronoUnit defaultUnit) {
TypeDescriptor targetType = mock(TypeDescriptor.class); TypeDescriptor targetType = mock(TypeDescriptor.class);
DurationUnit annotation = AnnotationUtils.synthesizeAnnotation( DefaultDurationUnit annotation = AnnotationUtils.synthesizeAnnotation(
Collections.singletonMap("value", defaultUnit), DurationUnit.class, null); Collections.singletonMap("value", defaultUnit), DefaultDurationUnit.class, null);
given(targetType.getAnnotation(DurationUnit.class)).willReturn(annotation); given(targetType.getAnnotation(DefaultDurationUnit.class)).willReturn(annotation);
return (Duration) this.converter.convert(source, TypeDescriptor.forObject(source), return (Duration) this.converter.convert(source, TypeDescriptor.forObject(source),
targetType); targetType);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment