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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user