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

Adds an afterStart pseudo-event to LoomServer observable by Router implementations #9655

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -225,6 +225,8 @@ private void startIt() {
+ uptime + " milliseconds since JVM startup. "
+ "Java " + Runtime.version());

fireAfterStart();

if ("!".equals(System.getProperty(EXIT_ON_STARTED_KEY))) {
LOGGER.log(System.Logger.Level.INFO, String.format("Exiting, -D%s set.", EXIT_ON_STARTED_KEY));
// we need to run the system exit on a different thread, to correctly finish whatever was happening on main
Expand All @@ -239,6 +241,10 @@ private void startIt() {
}
}

private void fireAfterStart() {
listeners.values().forEach(l -> l.router().afterStart(this));
}

private void registerShutdownHook() {
this.shutdownHandler = new ServerShutdownHandler(listeners, startFutures, running, context.id());
Main.addShutdownHandler(this.shutdownHandler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -61,6 +61,14 @@ static Router empty() {
*/
void beforeStart();

/**
* This is called after the server's listeners have successfully started.
*
* @param webServer the {@link WebServer} that has successfully started
*/
default void afterStart(WebServer webServer) {
}

/**
* List of all conifgured routings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public void beforeStart() {
}
}

@Override
public void afterStart(WebServer webServer) {
for (Routing value : routings.values()) {
value.afterStart(webServer);
}
}

@Override
public List<? extends Routing> routings() {
return List.copyOf(routings.values());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,6 +26,14 @@ public interface ServerLifecycle {
default void beforeStart() {
}

/**
* After server start.
*
* @param webServer the {@link WebServer} that was started
*/
default void afterStart(WebServer webServer) {
}

/**
* After server stop.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -212,6 +212,10 @@ int port() {
return connectedPort;
}

Router router() {
return router;
}

InetSocketAddress configuredAddress() {
return configuredAddress;
}
Expand Down
Loading