Search in sources :

Example 16 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project druid by druid-io.

the class JettyServerModule method makeJettyServer.

static Server makeJettyServer(DruidNode node, ServerConfig config) {
    final QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.setMinThreads(config.getNumThreads());
    threadPool.setMaxThreads(config.getNumThreads());
    threadPool.setDaemon(true);
    final Server server = new Server(threadPool);
    // Without this bean set, the default ScheduledExecutorScheduler runs as non-daemon, causing lifecycle hooks to fail
    // to fire on main exit. Related bug: https://github.com/druid-io/druid/pull/1627
    server.addBean(new ScheduledExecutorScheduler("JettyScheduler", true), true);
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(node.getPort());
    connector.setIdleTimeout(Ints.checkedCast(config.getMaxIdleTime().toStandardDuration().getMillis()));
    // workaround suggested in -
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=435322#c66 for jetty half open connection issues during failovers
    connector.setAcceptorPriorityDelta(-1);
    List<ConnectionFactory> monitoredConnFactories = new ArrayList<>();
    for (ConnectionFactory cf : connector.getConnectionFactories()) {
        monitoredConnFactories.add(new JettyMonitoringConnectionFactory(cf, activeConnections));
    }
    connector.setConnectionFactories(monitoredConnFactories);
    server.setConnectors(new Connector[] { connector });
    return server;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ArrayList(java.util.ArrayList)

Example 17 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project airlift by airlift.

the class JettyHttpClient method createScheduler.

private static Scheduler createScheduler(String name, int timeoutConcurrency, int timeoutThreads) {
    Scheduler scheduler;
    String threadName = "http-client-" + name + "-scheduler";
    if ((timeoutConcurrency == 1) && (timeoutThreads == 1)) {
        scheduler = new ScheduledExecutorScheduler(threadName, true);
    } else {
        checkArgument(timeoutConcurrency >= 1, "timeoutConcurrency must be at least one");
        int threads = max(1, timeoutThreads / timeoutConcurrency);
        scheduler = new ConcurrentScheduler(timeoutConcurrency, threads, threadName);
    }
    try {
        scheduler.start();
    } catch (Exception e) {
        throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
    return scheduler;
}
Also used : ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) GeneralSecurityException(java.security.GeneralSecurityException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 18 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project dropwizard by dropwizard.

the class Http2ConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    // HTTP/2 requires that a server MUST support TLSv1.2 or higher and TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher
    // See https://datatracker.ietf.org/doc/html/rfc7540#section-9.2
    setSupportedProtocols(Arrays.asList("TLSv1.3", "TLSv1.2"));
    checkSupportedCipherSuites();
    // Setup connection factories
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory http1 = buildHttpConnectionFactory(httpConfig);
    final HTTP2ServerConnectionFactory http2 = new HTTP2ServerConnectionFactory(httpConfig);
    http2.setMaxConcurrentStreams(maxConcurrentStreams);
    http2.setInitialStreamRecvWindow(initialStreamRecvWindow);
    final NegotiatingServerConnectionFactory alpn = new ALPNServerConnectionFactory();
    // Speak HTTP 1.1 over TLS if negotiation fails
    alpn.setDefaultProtocol("http/1.1");
    final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory.Server());
    sslContextFactory.addLifeCycleListener(logSslParameters(sslContextFactory));
    server.addBean(sslContextFactory);
    server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
    // We should use ALPN as a negotiation protocol. Old clients that don't support it will be served
    // via HTTPS. New clients, however, that want to use HTTP/2 will use TLS with ALPN extension.
    // If negotiation succeeds, the client and server switch to HTTP/2 protocol.
    final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, "alpn");
    return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool, new InstrumentedConnectionFactory(sslConnectionFactory, metrics.timer(httpConnections())), alpn, http2, http1);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslReload(io.dropwizard.jetty.SslReload) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ALPNServerConnectionFactory(org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) NegotiatingServerConnectionFactory(org.eclipse.jetty.server.NegotiatingServerConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 19 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project dropwizard by dropwizard.

the class Http2CConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    // Prepare connection factories for HTTP/2c
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory http11 = buildHttpConnectionFactory(httpConfig);
    final HTTP2ServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(httpConfig);
    http2c.setMaxConcurrentStreams(maxConcurrentStreams);
    http2c.setInitialStreamRecvWindow(initialStreamRecvWindow);
    // new protocol.
    return buildConnector(server, new ScheduledExecutorScheduler(), buildBufferPool(), name, threadPool, new InstrumentedConnectionFactory(http11, metrics.timer(httpConnections())), http2c);
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) HTTP2ServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Example 20 with ScheduledExecutorScheduler

use of org.eclipse.jetty.util.thread.ScheduledExecutorScheduler in project dropwizard by dropwizard.

the class HttpsConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, @Nullable ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final SslContextFactory sslContextFactory = configureSslContextFactory(new SslContextFactory.Server());
    sslContextFactory.addLifeCycleListener(logSslParameters(sslContextFactory));
    server.addBean(sslContextFactory);
    server.addBean(new SslReload(sslContextFactory, this::configureSslContextFactory));
    final SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.toString());
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new InstrumentedConnectionFactory(sslConnectionFactory, metrics.timer(httpConnections())), httpConnectionFactory);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) InstrumentedConnectionFactory(com.codahale.metrics.jetty9.InstrumentedConnectionFactory)

Aggregations

ScheduledExecutorScheduler (org.eclipse.jetty.util.thread.ScheduledExecutorScheduler)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)9 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 Server (org.eclipse.jetty.server.Server)7 Scheduler (org.eclipse.jetty.util.thread.Scheduler)7 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 IOException (java.io.IOException)5 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)5 InstrumentedConnectionFactory (com.codahale.metrics.jetty9.InstrumentedConnectionFactory)4 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)4 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ArrayList (java.util.ArrayList)3 ServletException (javax.servlet.ServletException)3 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HTTP2ServerConnectionFactory (org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory)2 ForwardedRequestCustomizer (org.eclipse.jetty.server.ForwardedRequestCustomizer)2 Request (org.eclipse.jetty.server.Request)2