in services/minho-http/src/main/java/org/apache/karaf/minho/web/jetty/JettyWebContainerService.java [56:121]
public void onRegister(ServiceRegistry serviceRegistry) throws Exception {
ConfigService configService = serviceRegistry.get(ConfigService.class);
if (configService == null) {
log.warning("ConfigService is not found in the registry");
}
log.info("Starting HTTP service");
int maxThreads = (configService != null && configService.getProperty(HTTP_MAX_THREADS) != null) ? Integer.parseInt(configService.getProperty(HTTP_MAX_THREADS)) : 200;
int minThreads = (configService != null && configService.getProperty(HTTP_MIN_THREADS) != null) ? Integer.parseInt(configService.getProperty(HTTP_MIN_THREADS)) : Math.min(8, maxThreads);
int idleTimeout = (configService != null && configService.getProperty(HTTP_IDLE_TIMEOUT) != null) ? Integer.parseInt(configService.getProperty(HTTP_IDLE_TIMEOUT)) : 60000;
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, idleTimeout);
threadPool.setName("minho-http");
log.info("Creating HTTP queued thread pool");
log.info("\tmaxThreads: " + maxThreads);
log.info("\tminThreads: " + minThreads);
log.info("\tidleTimeout: " + idleTimeout);
server = new Server(threadPool);
int acceptors = (configService != null && configService.getProperty(HTTP_ACCEPTORS) != null) ? Integer.parseInt(configService.getProperty(HTTP_ACCEPTORS)) : -1;
int selectors = (configService != null && configService.getProperty(HTTP_SELECTORS) != null) ? Integer.parseInt(configService.getProperty(HTTP_SELECTORS)) : -1;
int port = (configService != null && configService.getProperty(HTTP_PORT) != null) ? Integer.parseInt(configService.getProperty(HTTP_PORT)) : 8080;
String host = (configService != null && configService.getProperty(HTTP_HOST) != null) ? configService.getProperty(HTTP_HOST) : "0.0.0.0";
int acceptQueueSize = (configService != null && configService.getProperty(HTTP_ACCEPT_QUEUE_SIZE) != null) ? Integer.parseInt(configService.getProperty(HTTP_ACCEPT_QUEUE_SIZE)) : 0;
log.info("Creating HTTP server connector");
log.info("\tacceptors: " + acceptors);
log.info("\tselectors: " + selectors);
log.info("\tport: " + port);
log.info("\thost: " + host);
log.info("\tacceptQueueSize: " + acceptQueueSize);
connector = new ServerConnector(server, acceptors, selectors, new HttpConnectionFactory());
connector.setPort(port);
connector.setHost(host);
connector.setAcceptQueueSize(acceptQueueSize);
server.addConnector(connector);
servlets = new ServletContextHandler(ServletContextHandler.SESSIONS);
servlets.setContextPath("/");
server.setHandler(servlets);
addServlets(serviceRegistry);
server.insertHandler(new StatisticsHandler());
LifeCycleService lifeCycleService = serviceRegistry.get(LifeCycleService.class);
lifeCycleService.onStart(() -> {
try {
server.start();
// server.join();
} catch (Exception e) {
throw new RuntimeException("Can't start HTTP service", e);
}
});
lifeCycleService.onShutdown(() -> {
try {
connector.close();
server.stop();
} catch (Exception e) {
log.warning("Can't stop HTTP service: " + e.getMessage());
}
});
}