use of org.webpieces.webserver.impl.WebServerImpl in project webpieces by deanhiller.
the class WebServerFactory method create.
public static WebServer create(WebServerConfig config, RouterConfig routerConfig, TemplateConfig templateConfig, Arguments args) {
if (!routerConfig.getMetaFile().exists())
throw new RuntimeException("file not found=" + routerConfig.getMetaFile());
try {
// logback called getLocalhost(resulting in 5 seconds)
// H2 called getLocalHost like 3 times(resulting in 15 more seconds)
// overall, it really screwed the startup time!!
// https://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds/33289897#33289897
log.info("Checking timing on getLocalHost (seems very bad on many MAC computers) which makes webpieces startup look slow(and we like a fast startup");
long start = System.currentTimeMillis();
InetAddress.getLocalHost();
long totalTimeSeconds = (System.currentTimeMillis() - start) / 1000;
if (totalTimeSeconds > 3)
throw new IllegalStateException("Your computer configuration is messed up. getLocalHost " + "is taking longer\nthan 3 seconds. FIX THIS NOW!!! You can typically edit your hosts file\n" + "to do so. See https://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds/33289897#33289897 for more info");
} catch (UnknownHostException e) {
throw SneakyThrow.sneak(e);
}
Module allModules = getModules(config, routerConfig, templateConfig, args);
Module platformOverrides = config.getPlatformOverrides();
if (platformOverrides != null)
allModules = Modules.override(allModules).with(platformOverrides);
Injector injector = Guice.createInjector(allModules);
WebServerImpl serverImpl = injector.getInstance(WebServerImpl.class);
// special case and I HATE statics but if customer swapped in their own FutureUtil, then we replace it with theirs here. If they didn't
// this literally just sets the same FutureUtil into the filters
FutureHelper util = injector.getInstance(FutureHelper.class);
Filter.setFutureUtil(util);
// configure must be called as after configured, Arguments.checkConsumedCorrectly must
serverImpl.configureSync(args);
// be called before start is called on the webserver
return serverImpl;
}
Aggregations