use of io.undertow.server.handlers.GracefulShutdownHandler in project adeptj-runtime by AdeptJ.
the class Server method rootHandler.
/**
* Chaining of Undertow {@link HttpHandler} instances as follows.
* <p>
* 1. GracefulShutdownHandler
* 2. RequestLimitingHandler
* 3. AllowedMethodsHandler
* 4. PredicateHandler which resolves to either RedirectHandler or SetHeadersHandler
* 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
* 5. And Finally ServletInitialHandler
*
* @param servletInitialHandler the {@link io.undertow.servlet.handlers.ServletInitialHandler}
* @return GracefulShutdownHandler as the root handler
*/
private GracefulShutdownHandler rootHandler(HttpHandler servletInitialHandler) {
Config cfg = Objects.requireNonNull(this.cfgReference.get());
Map<HttpString, String> headers = new HashMap<>();
headers.put(HttpString.tryFromString(HEADER_SERVER), cfg.getString(KEY_HEADER_SERVER));
if (Environment.isDev()) {
headers.put(HttpString.tryFromString(HEADER_X_POWERED_BY), Version.getFullVersionString());
}
HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeadersHandler(new RequestBufferingHandler(servletInitialHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS))), headers) : new SetHeadersHandler(servletInitialHandler, headers);
return Handlers.gracefulShutdown(new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)), new AllowedMethodsHandler(Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()), Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler), this.allowedMethods(cfg))));
}
use of io.undertow.server.handlers.GracefulShutdownHandler in project spring-boot by spring-projects.
the class UndertowWebServer method createHttpHandler.
protected HttpHandler createHttpHandler() {
HttpHandler handler = null;
for (HttpHandlerFactory factory : this.httpHandlerFactories) {
handler = factory.getHandler(handler);
if (handler instanceof Closeable) {
this.closeables.add((Closeable) handler);
}
if (handler instanceof GracefulShutdownHandler) {
Assert.isNull(this.gracefulShutdown, "Only a single GracefulShutdownHandler can be defined");
this.gracefulShutdown = (GracefulShutdownHandler) handler;
}
}
return handler;
}
use of io.undertow.server.handlers.GracefulShutdownHandler in project oap by oaplatform.
the class NioHttpServer method start.
public void start() {
Undertow.Builder builder = Undertow.builder().addHttpListener(port, "0.0.0.0").setSocketOption(Options.REUSE_ADDRESSES, true).setSocketOption(Options.TCP_NODELAY, tcpNodelay).setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, true);
if (backlog > 0)
builder.setSocketOption(Options.BACKLOG, backlog);
if (ioThreads > 0)
builder.setIoThreads(ioThreads);
if (workerThreads > 0)
builder.setWorkerThreads(workerThreads);
if (idleTimeout > 0)
builder.setServerOption(UndertowOptions.IDLE_TIMEOUT, (int) idleTimeout);
if (maxEntitySize > 0)
builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, maxEntitySize);
if (maxParameters > 0)
builder.setServerOption(UndertowOptions.MAX_PARAMETERS, maxParameters);
if (maxHeaders > 0)
builder.setServerOption(UndertowOptions.MAX_HEADERS, maxHeaders);
if (maxHeaderSize > 0)
builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE, maxHeaderSize);
if (statistics)
builder.setServerOption(UndertowOptions.ENABLE_STATISTICS, true);
builder.setServerOption(UndertowOptions.ALWAYS_SET_DATE, alwaysSetDate);
builder.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, alwaysSetKeepAlive);
io.undertow.server.HttpHandler handler = pathHandler;
if (forceCompressionSupport) {
handler = new EncodingHandler(handler, contentEncodingRepository);
handler = new RequestEncodingHandler(handler).addEncoding("gzip", GzipStreamSourceConduit.WRAPPER).addEncoding("deflate", InflatingStreamSourceConduit.WRAPPER);
}
handler = new BlockingHandler(handler);
handler = new GracefulShutdownHandler(handler);
builder.setHandler(handler);
server = builder.build();
server.start();
log.info("port {} statistics {} ioThreads {} workerThreads {}", port, statistics, server.getWorker().getMXBean().getIoThreadCount(), server.getWorker().getMXBean().getMaxWorkerPoolSize());
if (statistics) {
for (var listenerInfo : server.getListenerInfo()) {
var sa = (InetSocketAddress) listenerInfo.getAddress();
var port = String.valueOf(sa.getPort());
ConnectorStatistics connectorStatistics = listenerInfo.getConnectorStatistics();
Metrics.gauge("nio_requests", Tags.of("port", port, "type", "total"), connectorStatistics, ConnectorStatistics::getRequestCount);
Metrics.gauge("nio_requests", Tags.of("port", port, "type", "active"), connectorStatistics, ConnectorStatistics::getActiveRequests);
Metrics.gauge("nio_requests", Tags.of("port", port, "type", "errors"), connectorStatistics, ConnectorStatistics::getErrorCount);
Metrics.gauge("nio_connections", Tags.of("port", port, "type", "active"), connectorStatistics, ConnectorStatistics::getActiveConnections);
Metrics.gauge("nio_pool_size", Tags.of("port", port, "name", "worker", "type", "active"), server, server -> server.getWorker().getMXBean().getWorkerPoolSize());
Metrics.gauge("nio_pool_size", Tags.of("port", port, "name", "worker", "type", "core"), server, server -> server.getWorker().getMXBean().getCoreWorkerPoolSize());
Metrics.gauge("nio_pool_size", Tags.of("port", port, "name", "worker", "type", "max"), server, server -> server.getWorker().getMXBean().getMaxWorkerPoolSize());
Metrics.gauge("nio_pool_size", Tags.of("port", port, "name", "worker", "type", "busy"), server, server -> server.getWorker().getMXBean().getBusyWorkerThreadCount());
Metrics.gauge("nio_pool_size", Tags.of("port", port, "name", "worker", "type", "queue"), server, server -> server.getWorker().getMXBean().getWorkerQueueSize());
}
}
}
Aggregations