Update configuration properties to use Duration
Update appropriate configuration properties to use the `Duration` type, rather than an ad-hoc mix of milliseconds or seconds. Configuration properties can now be defined in a consistent and readable way. For example `server.session.timeout=5m`. Properties that were previously declared using seconds are annotated with `@DurationUnit` to ensure a smooth upgrade experience. For example `server.session.timeout=20` continues to mean 20 seconds. Fixes gh-11080
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.devtools.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -62,10 +63,6 @@ public class DevToolsProperties {
|
||||
+ "META-INF/resources/**,resources/**,static/**,public/**,templates/**,"
|
||||
+ "**/*Test.class,**/*Tests.class,git.properties,META-INF/build-info.properties";
|
||||
|
||||
private static final long DEFAULT_RESTART_POLL_INTERVAL = 1000;
|
||||
|
||||
private static final long DEFAULT_RESTART_QUIET_PERIOD = 400;
|
||||
|
||||
/**
|
||||
* Enable automatic restart.
|
||||
*/
|
||||
@@ -82,15 +79,15 @@ public class DevToolsProperties {
|
||||
private String additionalExclude;
|
||||
|
||||
/**
|
||||
* Amount of time (in milliseconds) to wait between polling for classpath changes.
|
||||
* Amount of time to wait between polling for classpath changes.
|
||||
*/
|
||||
private long pollInterval = DEFAULT_RESTART_POLL_INTERVAL;
|
||||
private Duration pollInterval = Duration.ofSeconds(1);
|
||||
|
||||
/**
|
||||
* Amount of quiet time (in milliseconds) required without any classpath changes
|
||||
* before a restart is triggered.
|
||||
* Amount of quiet time required without any classpath changes before a restart is
|
||||
* triggered.
|
||||
*/
|
||||
private long quietPeriod = DEFAULT_RESTART_QUIET_PERIOD;
|
||||
private Duration quietPeriod = Duration.ofMillis(400);
|
||||
|
||||
/**
|
||||
* Name of a specific file that when changed will trigger the restart check. If
|
||||
@@ -139,19 +136,19 @@ public class DevToolsProperties {
|
||||
this.additionalExclude = additionalExclude;
|
||||
}
|
||||
|
||||
public long getPollInterval() {
|
||||
public Duration getPollInterval() {
|
||||
return this.pollInterval;
|
||||
}
|
||||
|
||||
public void setPollInterval(long pollInterval) {
|
||||
public void setPollInterval(Duration pollInterval) {
|
||||
this.pollInterval = pollInterval;
|
||||
}
|
||||
|
||||
public long getQuietPeriod() {
|
||||
public Duration getQuietPeriod() {
|
||||
return this.quietPeriod;
|
||||
}
|
||||
|
||||
public void setQuietPeriod(long quietPeriod) {
|
||||
public void setQuietPeriod(Duration quietPeriod) {
|
||||
this.quietPeriod = quietPeriod;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.devtools.filewatch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -41,9 +42,9 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class FileSystemWatcher {
|
||||
|
||||
private static final long DEFAULT_POLL_INTERVAL = 1000;
|
||||
private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofMillis(1000);
|
||||
|
||||
private static final long DEFAULT_QUIET_PERIOD = 400;
|
||||
private static final Duration DEFAULT_QUIET_PERIOD = Duration.ofMillis(400);
|
||||
|
||||
private final List<FileChangeListener> listeners = new ArrayList<>();
|
||||
|
||||
@@ -77,14 +78,17 @@ public class FileSystemWatcher {
|
||||
* @param quietPeriod the amount of time required after a change has been detected to
|
||||
* ensure that updates have completed
|
||||
*/
|
||||
public FileSystemWatcher(boolean daemon, long pollInterval, long quietPeriod) {
|
||||
Assert.isTrue(pollInterval > 0, "PollInterval must be positive");
|
||||
Assert.isTrue(quietPeriod > 0, "QuietPeriod must be positive");
|
||||
Assert.isTrue(pollInterval > quietPeriod,
|
||||
public FileSystemWatcher(boolean daemon, Duration pollInterval,
|
||||
Duration quietPeriod) {
|
||||
Assert.notNull(pollInterval, "PollInterval must not be null");
|
||||
Assert.notNull(quietPeriod, "QuietPeriod must not be null");
|
||||
Assert.isTrue(pollInterval.toMillis() > 0, "PollInterval must be positive");
|
||||
Assert.isTrue(quietPeriod.toMillis() > 0, "QuietPeriod must be positive");
|
||||
Assert.isTrue(pollInterval.toMillis() > quietPeriod.toMillis(),
|
||||
"PollInterval must be greater than QuietPeriod");
|
||||
this.daemon = daemon;
|
||||
this.pollInterval = pollInterval;
|
||||
this.quietPeriod = quietPeriod;
|
||||
this.pollInterval = pollInterval.toMillis();
|
||||
this.quietPeriod = quietPeriod.toMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.devtools.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -120,7 +121,7 @@ public class LocalDevToolsAutoConfigurationTests {
|
||||
public void resourceCachePeriodIsZero() throws Exception {
|
||||
this.context = initializeAndRun(WebResourcesConfig.class);
|
||||
ResourceProperties properties = this.context.getBean(ResourceProperties.class);
|
||||
assertThat(properties.getCachePeriod()).isEqualTo(0);
|
||||
assertThat(properties.getCachePeriod()).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.devtools.classpath;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -104,7 +105,8 @@ public class ClassPathFileSystemWatcherTests {
|
||||
|
||||
@Bean
|
||||
public ClassPathFileSystemWatcher watcher() {
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(false, 100, 10);
|
||||
FileSystemWatcher watcher = new FileSystemWatcher(false,
|
||||
Duration.ofMillis(100), Duration.ofMillis(10));
|
||||
URL[] urls = this.environment.getProperty("urls", URL[].class);
|
||||
return new ClassPathFileSystemWatcher(
|
||||
new MockFileSystemWatcherFactory(watcher), restartStrategy(), urls);
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -66,21 +67,21 @@ public class FileSystemWatcherTests {
|
||||
public void pollIntervalMustBePositive() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("PollInterval must be positive");
|
||||
new FileSystemWatcher(true, 0, 1);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(0), Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quietPeriodMustBePositive() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("QuietPeriod must be positive");
|
||||
new FileSystemWatcher(true, 1, 0);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pollIntervalMustBeGreaterThanQuietPeriod() throws Exception {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("PollInterval must be greater than QuietPeriod");
|
||||
new FileSystemWatcher(true, 1, 1);
|
||||
new FileSystemWatcher(true, Duration.ofMillis(1), Duration.ofMillis(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,7 +273,8 @@ public class FileSystemWatcherTests {
|
||||
}
|
||||
|
||||
private void setupWatcher(long pollingInterval, long quietPeriod) {
|
||||
this.watcher = new FileSystemWatcher(false, pollingInterval, quietPeriod);
|
||||
this.watcher = new FileSystemWatcher(false, Duration.ofMillis(pollingInterval),
|
||||
Duration.ofMillis(quietPeriod));
|
||||
this.watcher.addListener(
|
||||
(changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user