Search in sources :

Example 1 with CompressionConfig

use of org.glassfish.grizzly.http.CompressionConfig in project graylog2-server by Graylog2.

the class JerseyService method setUp.

private HttpServer setUp(String namePrefix, URI listenUri, SSLEngineConfigurator sslEngineConfigurator, int threadPoolSize, int selectorRunnersCount, int maxInitialLineLength, int maxHeaderSize, boolean enableGzip, boolean enableCors, Set<Resource> additionalResources, String[] controllerPackages) throws GeneralSecurityException, IOException {
    final ResourceConfig resourceConfig = buildResourceConfig(enableCors, additionalResources, controllerPackages);
    final HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(listenUri, resourceConfig, sslEngineConfigurator != null, sslEngineConfigurator, false);
    final NetworkListener listener = httpServer.getListener("grizzly");
    listener.setMaxHttpHeaderSize(maxInitialLineLength);
    listener.setMaxRequestHeaders(maxHeaderSize);
    final ExecutorService workerThreadPoolExecutor = instrumentedExecutor(namePrefix + "-worker-executor", namePrefix + "-worker-%d", threadPoolSize);
    listener.getTransport().setWorkerThreadPool(workerThreadPoolExecutor);
    // The Grizzly default value is equal to `Runtime.getRuntime().availableProcessors()` which doesn't make
    // sense for Graylog because we are not mainly a web server.
    // See "Selector runners count" at https://grizzly.java.net/bestpractices.html for details.
    listener.getTransport().setSelectorRunnersCount(selectorRunnersCount);
    listener.setDefaultErrorPageGenerator(errorPageGenerator);
    if (enableGzip) {
        final CompressionConfig compressionConfig = listener.getCompressionConfig();
        compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON);
        compressionConfig.setCompressionMinSize(512);
    }
    return httpServer;
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) CompressionConfig(org.glassfish.grizzly.http.CompressionConfig)

Aggregations

InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 ExecutorService (java.util.concurrent.ExecutorService)1 CompressionConfig (org.glassfish.grizzly.http.CompressionConfig)1 HttpServer (org.glassfish.grizzly.http.server.HttpServer)1 NetworkListener (org.glassfish.grizzly.http.server.NetworkListener)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1