Skip to content

Commit

Permalink
Improved startup time.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Nov 2, 2018
1 parent 45e6b8e commit 11b554f
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/main/java/io/sinistral/proteus/ProteusApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,32 +69,34 @@ public class ProteusApplication

@Inject
@Named("registeredControllers")
protected Set<Class<?>> registeredControllers;
public Set<Class<?>> registeredControllers;

@Inject
@Named("registeredEndpoints")
protected Set<EndpointInfo> registeredEndpoints;
public Set<EndpointInfo> registeredEndpoints;

@Inject
@Named("registeredServices")
protected Set<Class<? extends BaseService>> registeredServices;
public Set<Class<? extends BaseService>> registeredServices;

@Inject
protected RoutingHandler router;
public RoutingHandler router;

@Inject
protected Config config;
public Config config;

protected List<Class<? extends Module>> registeredModules = new ArrayList<>();
public List<Class<? extends Module>> registeredModules = new ArrayList<>();

protected Injector injector = null;
protected ServiceManager serviceManager = null;
protected Undertow undertow = null;
protected Class<? extends HttpHandler> rootHandlerClass;
protected HttpHandler rootHandler;
protected AtomicBoolean running = new AtomicBoolean(false);
protected List<Integer> ports = new ArrayList<>();
protected Function<Undertow.Builder, Undertow.Builder> serverConfigurationFunction = null;
public Injector injector = null;
public ServiceManager serviceManager = null;
public Undertow undertow = null;
public Class<? extends HttpHandler> rootHandlerClass;
public HttpHandler rootHandler;
public AtomicBoolean running = new AtomicBoolean(false);
public List<Integer> ports = new ArrayList<>();
public Function<Undertow.Builder, Undertow.Builder> serverConfigurationFunction = null;

public Duration startupDuration;

public ProteusApplication()
{
Expand Down Expand Up @@ -126,6 +129,8 @@ public void start()
log.warn("Server has already started...");
return;
}

final long startTime = System.currentTimeMillis();

log.info("Configuring modules: " + registeredModules);

Expand Down Expand Up @@ -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);
Expand All @@ -176,7 +177,7 @@ public void healthy()

printStatus();

running.set(true);
running.set(true);
}

public void failure(Service service)
Expand All @@ -201,7 +202,14 @@ public void run()
}
});

buildServer();

undertow.start();

serviceManager.startAsync();




}

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 11b554f

Please sign in to comment.