本文整理汇总了Java中io.undertow.Handlers.gracefulShutdown方法的典型用法代码示例。如果您正苦于以下问题:Java Handlers.gracefulShutdown方法的具体用法?Java Handlers.gracefulShutdown怎么用?Java Handlers.gracefulShutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.Handlers
的用法示例。
在下文中一共展示了Handlers.gracefulShutdown方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rootHandler
import io.undertow.Handlers; //导入方法依赖的package包/类
private static GracefulShutdownHandler rootHandler(HttpHandler headersHandler, Config cfg) {
return Handlers.gracefulShutdown(
new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)),
new AllowedMethodsHandler(predicateHandler(headersHandler), allowedMethods(cfg))));
}
示例2: getHandlers
import io.undertow.Handlers; //导入方法依赖的package包/类
private HttpHandler getHandlers(SpurOptions options) {
// Path handler
PathTemplateHandler pathTemplateHandler = Handlers.pathTemplate();
endpointsMap.forEach((path, methodEndpointMap) -> pathTemplateHandler.add(path, new HttpHandler() {
public void handleRequest(HttpServerExchange exchange) throws Exception {
// non-blocking
if (options.blockableHandlersEnabled && exchange.isInIoThread()) {
// LOGGER.info("Is in IO thread, dispatching for blockableHandlersEnabled...");
exchange.dispatch(this);
return;
}
// handler code
// LOGGER.info("STARTING Async");
invokePathTemplateHandler(options, methodEndpointMap, exchange);
}
}));
// Websocket
if (!webSocketHandlerMap.isEmpty()) {
webSocketHandlerMap.forEach((pathPrefix, webSocketHandler) -> {
LOGGER.info("Adding WS for path: " + webSocketHandler.getPath());
addWebSocketHandler(pathTemplateHandler, webSocketHandler);
});
}
// SSE
if (!sseHandlerMap.isEmpty()) {
sseHandlerMap.forEach(pathTemplateHandler::add);
}
// CORS
HttpHandler httpHandler = Handlers.predicate(exchange -> isValidCorsOrigin(options, getRequestHeader(exchange, Headers.ORIGIN)),
new CorsHandler(pathTemplateHandler), pathTemplateHandler);
// Gzip
if (options.gzipEnabled) {
httpHandler = new EncodingHandler(new ContentEncodingRepository().addEncodingHandler("gzip", new GzipEncodingProvider(), 50,
Predicates.maxContentSize(options.gzipMaxSize))).setNext(httpHandler);
}
// Custom handlers
for (RequestFilter requestFilter : requestFilters) {
httpHandler = Handlers.predicate(requestFilter.getAssertionPredicate(), httpHandler, requestFilter.getFailureHandler());
}
// Graceful shutdown
httpHandler = Handlers.gracefulShutdown(httpHandler);
// Basic auth
if (!options.basicAuthUser.isEmpty() && !options.basicAuthPassword.isEmpty()) {
httpHandler = new BasicAuthHandler(httpHandler, options.basicAuthUser, options.basicAuthPassword);
}
// Force HTTPS
if (options.forceHttps) {
httpHandler = Handlers.predicate(Predicates.secure(), httpHandler, new RedirectHttpsHandler());
}
return httpHandler;
}