Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
philwebb committed Dec 15, 2023
1 parent b08d441 commit 92a4a11
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,9 @@ public ConfigurableApplicationContext getApplicationContext() {

}

/**
* {@link SpringApplicationHook} decorator that ensures the hook is only used once.
*/
private static final class SingleUseSpringApplicationHook implements SpringApplicationHook {

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

/**
* <<<<<<< HEAD Starts a non-daemon thread to keep the JVM alive on
* {@link ContextRefreshedEvent}. Stops the thread on {@link ContextClosedEvent}.
* Starts a non-daemon thread to keep the JVM alive on {@link ContextRefreshedEvent}.
* Stops the thread on {@link ContextClosedEvent}.
*/
private static final class KeepAlive implements ApplicationListener<ApplicationContextEvent> {

Expand Down Expand Up @@ -1696,31 +1699,34 @@ private void stopKeepAliveThread() {

}

/**
* Strategy used to handle startup concerns.
*/
abstract static class Startup {

private Duration timeTakenToStarted;

abstract long startTime();
protected abstract long startTime();

abstract Long processUptime();
protected abstract Long processUptime();

abstract String action();
protected abstract String action();

final Duration started() {
long now = System.currentTimeMillis();
this.timeTakenToStarted = Duration.ofMillis(now - startTime());
return this.timeTakenToStarted;
}

Duration timeTakenToStarted() {
return this.timeTakenToStarted;
}

private Duration ready() {
long now = System.currentTimeMillis();
return Duration.ofMillis(now - startTime());
}

Duration timeTakenToStarted() {
return this.timeTakenToStarted;
}

static Startup create() {
ClassLoader classLoader = Startup.class.getClassLoader();
return (ClassUtils.isPresent("jdk.crac.management.CRaCMXBean", classLoader)
Expand All @@ -1730,61 +1736,61 @@ static Startup create() {

}

private static class CoordinatedRestoreAtCheckpointStartup extends Startup {
/**
* Standard {@link Startup} implementation.
*/
private static class StandardStartup extends Startup {

private final StandardStartup fallback = new StandardStartup();
private final Long startTime = System.currentTimeMillis();

@Override
Long processUptime() {
long uptime = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
return (uptime >= 0) ? uptime : this.fallback.processUptime();
protected long startTime() {
return this.startTime;
}

@Override
String action() {
if (restoreTime() >= 0) {
return "Restored";
protected Long processUptime() {
try {
return ManagementFactory.getRuntimeMXBean().getUptime();
}
catch (Throwable ex) {
return null;
}
return this.fallback.action();
}

private long restoreTime() {
return CRaCMXBean.getCRaCMXBean().getRestoreTime();
}

@Override
long startTime() {
long restoreTime = restoreTime();
if (restoreTime >= 0) {
return restoreTime;
}
return this.fallback.startTime();
protected String action() {
return "Started";
}

}

private static class StandardStartup extends Startup {
/**
* Coordinated-Restore-At-Checkpoint {@link Startup} implementation.
*/
private static class CoordinatedRestoreAtCheckpointStartup extends Startup {

private final Long startTime = System.currentTimeMillis();
private final StandardStartup fallback = new StandardStartup();

@Override
long startTime() {
return this.startTime;
protected Long processUptime() {
long uptime = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
return (uptime >= 0) ? uptime : this.fallback.processUptime();
}

@Override
Long processUptime() {
try {
return ManagementFactory.getRuntimeMXBean().getUptime();
}
catch (Throwable ex) {
return null;
}
protected String action() {
return (restoreTime() >= 0) ? "Restored" : this.fallback.action();
}

private long restoreTime() {
return CRaCMXBean.getCRaCMXBean().getRestoreTime();
}

@Override
String action() {
return "Started";
protected long startTime() {
long restoreTime = restoreTime();
return (restoreTime >= 0) ? restoreTime : this.fallback.startTime();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,17 @@ static class TestStartup extends Startup {
}

@Override
long startTime() {
protected long startTime() {
return this.startTime;
}

@Override
Long processUptime() {
protected Long processUptime() {
return this.uptime;
}

@Override
String action() {
protected String action() {
return this.action;
}

Expand Down

0 comments on commit 92a4a11

Please sign in to comment.