use of io.undertow.server.handlers.encoding.RequestEncodingHandler in project oap by oaplatform.
the class NioHttpServer method bind.
public void bind(String prefix, HttpHandler handler, boolean compressionSupport) {
log.debug("bind {}", prefix);
Preconditions.checkNotNull(prefix);
Preconditions.checkArgument(!prefix.isEmpty());
io.undertow.server.HttpHandler httpHandler = exchange -> handler.handleRequest(new HttpServerExchange(exchange));
if (!forceCompressionSupport && compressionSupport) {
httpHandler = new EncodingHandler(httpHandler, contentEncodingRepository);
httpHandler = new RequestEncodingHandler(httpHandler).addEncoding("gzip", GzipStreamSourceConduit.WRAPPER).addEncoding("deflate", InflatingStreamSourceConduit.WRAPPER);
}
pathHandler.addPrefixPath(prefix, httpHandler);
}
use of io.undertow.server.handlers.encoding.RequestEncodingHandler 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