There is no obvious way to do so in version Helidon 4 SE
`public static void main(final String[] args) {
// load logging configuration
LogConfig.configureRuntime();
// initialize global config from default configuration
Config config = Config.create();
Config.global(config);
// Get webserver config from the "server" section of application.yaml
WebServerConfig.Builder builder = WebServer.builder();
WebServer server = builder
.config(config.get("server"))
.routing(Main::routing)
.build()
.start();
System.out.println("WEB server is up! http://localhost:" + server.port() + "/greet");
}`
I looked how this problem solved in Helidon SE 3:
server.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
But in Helison SE 4 method server.whenShutdown()
doesnt exists.
Here's one way.
In Helidon 4, any
Service
orHandler
you write (such as theGreetService
in the QuickStart SE example) and register with theHttpRouting
can implement thevoid afterStop()
method (as well asbeforeStart()
if you are so inclined).The following addition to
GreetService
in that example would accomplish the same as your example from 3.x:You would probably not want to add such a server shutdown announcement to more than one of your
Service
orHandler
implementations, but of course you can do whatever makes sense for you in each service's or handler'safterStop
code.