org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory Java Examples

The following examples show how to use org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedServerConfig.java    From secrets-proxy with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the embedded jetty server. The values are configured in <b>application.yaml</b>
 * file.
 *
 * @param port jetty server port
 * @param maxThreads thread pool min thread
 * @param minThreads thread pool max thread
 * @param idleTimeout maximum thread idle time
 * @param jmxEnabled true, if jetty jmx is enabled.
 * @return {@link JettyEmbeddedServletContainerFactory}
 */
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
    @Value("${server.port:8443}") final int port,
    @Value("${jetty.thread-pool.max-threads:200}") final int maxThreads,
    @Value("${jetty.thread-pool.min-threads:8}") final int minThreads,
    @Value("${jetty.thread-pool.idle-timeout:60000}") final int idleTimeout,
    @Value("${jetty.jmx.enabled:true}") final boolean jmxEnabled) {
  log.info("Configuring Jetty server.");
  final JettyEmbeddedServletContainerFactory factory =
      new JettyEmbeddedServletContainerFactory(port);
  factory.addServerCustomizers(
      server -> {
        final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
        threadPool.setMinThreads(minThreads);
        threadPool.setMaxThreads(maxThreads);
        threadPool.setIdleTimeout(idleTimeout);
        log.info("Server thread pool config:  " + server.getThreadPool());
        // Jetty JMX config.
        if (jmxEnabled) {
          log.info("Exposing Jetty managed beans to the JMX platform server.");
          server.addBean(new MBeanContainer(ManagementFactory.getPlatformMBeanServer()));
        }
      });
  return factory;
}
 
Example #2
Source File: JettyConfig.java    From nakadi with MIT License 6 votes vote down vote up
@Bean
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory(
        @Value("${server.port:8080}") final String port,
        @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
        @Value("${jetty.threadPool.minThreads:8}") final String minThreads,
        @Value("${jetty.threadPool.idleTimeout:60000}") final String idleTimeout) {
    final JettyEmbeddedServletContainerFactory factory =
            new JettyEmbeddedServletContainerFactory(Integer.valueOf(port));
    factory.addServerCustomizers((JettyServerCustomizer) server -> {
        final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
        threadPool.setMaxThreads(Integer.valueOf(maxThreads));
        threadPool.setMinThreads(Integer.valueOf(minThreads));
        threadPool.setIdleTimeout(Integer.valueOf(idleTimeout));

        final GzipHandler gzipHandler = new GzipHandler();
        gzipHandler.addIncludedMethods(HttpMethod.POST.asString());
        gzipHandler.setHandler(server.getHandler());
        gzipHandler.setSyncFlush(true);
        server.setHandler(gzipHandler);
    });
    return factory;
}
 
Example #3
Source File: MonetaSpringBootApplication.java    From moneta with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory servletContainer() {
	JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();

	factory.addServerCustomizers(new JettyServerCustomizer() {
		public void customize(final Server server) {
			// Tweak the connection pool used by Jetty to handle incoming
			// HTTP connections
			Integer localServerMaxThreads = deriveValue(serverMaxThreads,
					DEFAULT_SERVER_MAX_THREADS);
			Integer localServerMinThreads = deriveValue(serverMinThreads,
					DEFAULT_SERVER_MIN_THREADS);
			Integer localServerIdleTimeout = deriveValue(serverIdleTimeout,
					DEFAULT_SERVER_IDLE_TIMEOUT);

			logger.info("Container Max Threads={}", localServerMaxThreads);
			logger.info("Container Min Threads={}", localServerMinThreads);
			logger.info("Container Idle Timeout={}", localServerIdleTimeout);

			final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
			threadPool.setMaxThreads(Integer.valueOf(localServerMaxThreads));
			threadPool.setMinThreads(Integer.valueOf(localServerMinThreads));
			threadPool.setIdleTimeout(Integer.valueOf(localServerIdleTimeout));
		}
	});
	return factory;
}
 
Example #4
Source File: SpringTimeJettyCustomizer.java    From springtime with Apache License 2.0 4 votes vote down vote up
private void customizeThreadPool(JettyEmbeddedServletContainerFactory jettyFactory) {
	QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, 10000);
	jettyFactory.setThreadPool(threadPool);
}