Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display application name in shutdown message #4501

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ MainClassBuildItem build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
mv.setModifiers(Modifier.PUBLIC | Modifier.STATIC);

final ResultHandle appClassInstance = mv.newInstance(ofConstructor(appClassName));

// Set the application name
mv.invokeVirtualMethod(ofMethod(Application.class, "setName", void.class, String.class), appClassInstance,
mv.load(applicationInfo.getName()));

// run the app
mv.invokeVirtualMethod(ofMethod(Application.class, "run", void.class, String[].class), appClassInstance,
mv.getMethodParam(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class Application {
private final Lock stateLock = Locks.reentrantLock();
private final Condition stateCond = stateLock.newCondition();

private String name;
private int state = ST_INITIAL;
private volatile boolean shutdownRequested;
private static volatile Application currentApplication;
Expand Down Expand Up @@ -164,7 +165,7 @@ public final void stop() {
stateLock.lock();
try {
state = ST_STOPPED;
Timing.printStopTime();
Timing.printStopTime(name);
stateCond.signalAll();
} finally {
stateLock.unlock();
Expand All @@ -178,6 +179,10 @@ public static Application currentApplication() {

protected abstract void doStop();

public void setName(String name) {
this.name = name;
}

/**
* Run the application as if it were in a standalone JVM.
*/
Expand Down
10 changes: 6 additions & 4 deletions core/runtime/src/main/java/io/quarkus/runtime/Timing.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public static void printStartupTime(String name, String version, String quarkusV
final Logger logger = Logger.getLogger("io.quarkus");
//Use a BigDecimal so we can render in seconds with 3 digits precision, as requested:
final BigDecimal secondsRepresentation = convertToBigDecimalSeconds(bootTimeNanoSeconds);
String safeAppName = (name == null || name.isEmpty()) ? UNSET_VALUE : name;
String safeAppVersion = (version == null || version.isEmpty()) ? UNSET_VALUE : version;
String safeAppName = (name == null || name.trim().isEmpty()) ? UNSET_VALUE : name;
String safeAppVersion = (version == null || version.trim().isEmpty()) ? UNSET_VALUE : version;
if (UNSET_VALUE.equals(safeAppName) || UNSET_VALUE.equals(safeAppVersion)) {
logger.infof("Quarkus %s started in %ss. %s", quarkusVersion, secondsRepresentation, httpServerInfo);
} else {
Expand All @@ -71,11 +71,13 @@ public static void printStartupTime(String name, String version, String quarkusV
bootStartTime = -1;
}

public static void printStopTime() {
public static void printStopTime(String name) {
final long stopTimeNanoSeconds = System.nanoTime() - bootStopTime;
final Logger logger = Logger.getLogger("io.quarkus");
final BigDecimal secondsRepresentation = convertToBigDecimalSeconds(stopTimeNanoSeconds);
logger.infof("Quarkus stopped in %ss", secondsRepresentation);
logger.infof("%s stopped in %ss",
(UNSET_VALUE.equals(name) || name == null || name.trim().isEmpty()) ? "Quarkus" : name,
secondsRepresentation);
bootStopTime = -1;
}

Expand Down