From 11b554f1abdee1267425324358434c8023bf23af Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Fri, 2 Nov 2018 09:40:34 -0700 Subject: [PATCH] Improved startup time. --- .../sinistral/proteus/ProteusApplication.java | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/sinistral/proteus/ProteusApplication.java b/src/main/java/io/sinistral/proteus/ProteusApplication.java index 43b4413..62a40f7 100644 --- a/src/main/java/io/sinistral/proteus/ProteusApplication.java +++ b/src/main/java/io/sinistral/proteus/ProteusApplication.java @@ -12,6 +12,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.security.KeyStore; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -68,32 +69,34 @@ public class ProteusApplication @Inject @Named("registeredControllers") - protected Set> registeredControllers; + public Set> registeredControllers; @Inject @Named("registeredEndpoints") - protected Set registeredEndpoints; + public Set registeredEndpoints; @Inject @Named("registeredServices") - protected Set> registeredServices; + public Set> registeredServices; @Inject - protected RoutingHandler router; + public RoutingHandler router; @Inject - protected Config config; + public Config config; - protected List> registeredModules = new ArrayList<>(); + public List> registeredModules = new ArrayList<>(); - protected Injector injector = null; - protected ServiceManager serviceManager = null; - protected Undertow undertow = null; - protected Class rootHandlerClass; - protected HttpHandler rootHandler; - protected AtomicBoolean running = new AtomicBoolean(false); - protected List ports = new ArrayList<>(); - protected Function serverConfigurationFunction = null; + public Injector injector = null; + public ServiceManager serviceManager = null; + public Undertow undertow = null; + public Class rootHandlerClass; + public HttpHandler rootHandler; + public AtomicBoolean running = new AtomicBoolean(false); + public List ports = new ArrayList<>(); + public Function serverConfigurationFunction = null; + + public Duration startupDuration; public ProteusApplication() { @@ -126,6 +129,8 @@ public void start() log.warn("Server has already started..."); return; } + + final long startTime = System.currentTimeMillis(); log.info("Configuring modules: " + registeredModules); @@ -157,12 +162,8 @@ public void stopped() public void healthy() { - log.info("Services are healthy..."); - - buildServer(); - - undertow.start(); - + startupDuration = Duration.ofMillis(System.currentTimeMillis() - startTime); + for(ListenerInfo info : undertow.getListenerInfo()) { log.debug("listener info: " + info); @@ -176,7 +177,7 @@ public void healthy() printStatus(); - running.set(true); + running.set(true); } public void failure(Service service) @@ -201,7 +202,14 @@ public void run() } }); + buildServer(); + + undertow.start(); + serviceManager.startAsync(); + + + } @@ -432,9 +440,9 @@ public void printStatus() sb.append(printer.toString()); - sb.append("\nListening on: " + this.ports); - - sb.append("\n"); + sb.append("\nListening on: " + this.ports ); + + sb.append("\nStartup duration: " + this.startupDuration + "\n"); log.info(sb.toString()); }