Skip to content

Commit 92a4a11

Browse files
committed
Polish
1 parent b08d441 commit 92a4a11

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,9 @@ public ConfigurableApplicationContext getApplicationContext() {
16331633

16341634
}
16351635

1636+
/**
1637+
* {@link SpringApplicationHook} decorator that ensures the hook is only used once.
1638+
*/
16361639
private static final class SingleUseSpringApplicationHook implements SpringApplicationHook {
16371640

16381641
private final AtomicBoolean used = new AtomicBoolean();
@@ -1651,8 +1654,8 @@ public SpringApplicationRunListener getRunListener(SpringApplication springAppli
16511654
}
16521655

16531656
/**
1654-
* <<<<<<< HEAD Starts a non-daemon thread to keep the JVM alive on
1655-
* {@link ContextRefreshedEvent}. Stops the thread on {@link ContextClosedEvent}.
1657+
* Starts a non-daemon thread to keep the JVM alive on {@link ContextRefreshedEvent}.
1658+
* Stops the thread on {@link ContextClosedEvent}.
16561659
*/
16571660
private static final class KeepAlive implements ApplicationListener<ApplicationContextEvent> {
16581661

@@ -1696,31 +1699,34 @@ private void stopKeepAliveThread() {
16961699

16971700
}
16981701

1702+
/**
1703+
* Strategy used to handle startup concerns.
1704+
*/
16991705
abstract static class Startup {
17001706

17011707
private Duration timeTakenToStarted;
17021708

1703-
abstract long startTime();
1709+
protected abstract long startTime();
17041710

1705-
abstract Long processUptime();
1711+
protected abstract Long processUptime();
17061712

1707-
abstract String action();
1713+
protected abstract String action();
17081714

17091715
final Duration started() {
17101716
long now = System.currentTimeMillis();
17111717
this.timeTakenToStarted = Duration.ofMillis(now - startTime());
17121718
return this.timeTakenToStarted;
17131719
}
17141720

1721+
Duration timeTakenToStarted() {
1722+
return this.timeTakenToStarted;
1723+
}
1724+
17151725
private Duration ready() {
17161726
long now = System.currentTimeMillis();
17171727
return Duration.ofMillis(now - startTime());
17181728
}
17191729

1720-
Duration timeTakenToStarted() {
1721-
return this.timeTakenToStarted;
1722-
}
1723-
17241730
static Startup create() {
17251731
ClassLoader classLoader = Startup.class.getClassLoader();
17261732
return (ClassUtils.isPresent("jdk.crac.management.CRaCMXBean", classLoader)
@@ -1730,61 +1736,61 @@ static Startup create() {
17301736

17311737
}
17321738

1733-
private static class CoordinatedRestoreAtCheckpointStartup extends Startup {
1739+
/**
1740+
* Standard {@link Startup} implementation.
1741+
*/
1742+
private static class StandardStartup extends Startup {
17341743

1735-
private final StandardStartup fallback = new StandardStartup();
1744+
private final Long startTime = System.currentTimeMillis();
17361745

17371746
@Override
1738-
Long processUptime() {
1739-
long uptime = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
1740-
return (uptime >= 0) ? uptime : this.fallback.processUptime();
1747+
protected long startTime() {
1748+
return this.startTime;
17411749
}
17421750

17431751
@Override
1744-
String action() {
1745-
if (restoreTime() >= 0) {
1746-
return "Restored";
1752+
protected Long processUptime() {
1753+
try {
1754+
return ManagementFactory.getRuntimeMXBean().getUptime();
1755+
}
1756+
catch (Throwable ex) {
1757+
return null;
17471758
}
1748-
return this.fallback.action();
1749-
}
1750-
1751-
private long restoreTime() {
1752-
return CRaCMXBean.getCRaCMXBean().getRestoreTime();
17531759
}
17541760

17551761
@Override
1756-
long startTime() {
1757-
long restoreTime = restoreTime();
1758-
if (restoreTime >= 0) {
1759-
return restoreTime;
1760-
}
1761-
return this.fallback.startTime();
1762+
protected String action() {
1763+
return "Started";
17621764
}
17631765

17641766
}
17651767

1766-
private static class StandardStartup extends Startup {
1768+
/**
1769+
* Coordinated-Restore-At-Checkpoint {@link Startup} implementation.
1770+
*/
1771+
private static class CoordinatedRestoreAtCheckpointStartup extends Startup {
17671772

1768-
private final Long startTime = System.currentTimeMillis();
1773+
private final StandardStartup fallback = new StandardStartup();
17691774

17701775
@Override
1771-
long startTime() {
1772-
return this.startTime;
1776+
protected Long processUptime() {
1777+
long uptime = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
1778+
return (uptime >= 0) ? uptime : this.fallback.processUptime();
17731779
}
17741780

17751781
@Override
1776-
Long processUptime() {
1777-
try {
1778-
return ManagementFactory.getRuntimeMXBean().getUptime();
1779-
}
1780-
catch (Throwable ex) {
1781-
return null;
1782-
}
1782+
protected String action() {
1783+
return (restoreTime() >= 0) ? "Restored" : this.fallback.action();
1784+
}
1785+
1786+
private long restoreTime() {
1787+
return CRaCMXBean.getCRaCMXBean().getRestoreTime();
17831788
}
17841789

17851790
@Override
1786-
String action() {
1787-
return "Started";
1791+
protected long startTime() {
1792+
long restoreTime = restoreTime();
1793+
return (restoreTime >= 0) ? restoreTime : this.fallback.startTime();
17881794
}
17891795

17901796
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/StartupInfoLoggerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ static class TestStartup extends Startup {
110110
}
111111

112112
@Override
113-
long startTime() {
113+
protected long startTime() {
114114
return this.startTime;
115115
}
116116

117117
@Override
118-
Long processUptime() {
118+
protected Long processUptime() {
119119
return this.uptime;
120120
}
121121

122122
@Override
123-
String action() {
123+
protected String action() {
124124
return this.action;
125125
}
126126

0 commit comments

Comments
 (0)