Search in sources :

Example 6 with ExecutorThreadPool

use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project bayou by capergroup.

the class ApiSynthesisServerRest method start.

/**
 * Starts the server. Returns immediately. May only be called once.
 * @throws StartErrorException if there is a problem starting the server or this invocation of start is not the
 *                             first.
 */
// we don't allow start to be called twice just because the HTTP listen port should still be in use from the
// first start call since we have no stop action currently.
void start() throws StartErrorException {
    _logger.debug("entering");
    if (_startCalled) {
        _logger.debug("exiting");
        throw new StartErrorException("Already started");
    }
    _startCalled = true;
    /*
         * Create and configure the HTTP server that processes non-heartbeat related requests.
         */
    Server apiSynthServer;
    {
        /*
             * Set a bounded request queue because the default Jetty queue is unbounded and we want to defend
             * against an attack that makes a large volume of requests and exhausts the process' memory.
             */
        LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(_jettyTaskQueueSize.AsInt);
        ExecutorThreadPool pool = new ExecutorThreadPool(100, 100, 60, TimeUnit.SECONDS, queue);
        apiSynthServer = new Server(pool);
        /*
             * Configure the server to listen for requests on port _httpRequestListenPort.
             */
        ServerConnector connector = new ServerConnector(apiSynthServer, new HttpConnectionFactory());
        connector.setPort(_httpRequestListenPort.AsInt);
        apiSynthServer.addConnector(connector);
        /*
             * Configure routes.
             *
             * Pattern as per https://www.eclipse.org/jetty/documentation/9.4.x/embedding-jetty.html
             */
        ServletHandler handler = new ServletHandler();
        apiSynthServer.setHandler(handler);
        // register a servlet for performing apisynthesis
        handler.addServletWithMapping(ApiSynthesisServlet.class, "/apisynthesis");
        // register a servlet for collecting user feedback on result quality
        handler.addServletWithMapping(ApiSynthesisResultQualityFeedbackServlet.class, "/apisynthesisfeedback");
        /*
             * Code completion requests are sent via POST to ApiSynthesisServlet, however,
             * the site URL for the page that sends those POST requests can house that request body as a query parameter
             * for bookmarking.  That bookmarked URL then becomes the referrer of the POST request. As such there is a
             * relationship between the required header buffer size for this server and the allowed body size.
             *
             * As such ensure that we can accept headers as large as our max body size.
             */
        for (Connector c : apiSynthServer.getConnectors()) {
            HttpConfiguration config = c.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration();
            config.setRequestHeaderSize(_codeCompletionRequestBodyMaxBytesCount.AsInt);
        }
    }
    /*
         * Create and configure the HTTP server that processes heart beat requests.
         *
         * Use a different server than apiSynthServer because we don't want heart beat checks to be rejected
         * due to the bounded task queue used for apiSynthServer and inadvertently signal the system is unhealthy.
         *
         * We assume that the system is deployed in a way such that attackers do not have access to the heart beat
         * port and as such all heart beat requests are genuine (e.g. rate limited) and non-abusive.
         */
    Server healthCheckServer = new Server(_httpHeartbeatListenPort.AsInt);
    {
        /*
             * Configure routes.
             */
        // Pattern as per https://www.eclipse.org/jetty/documentation/9.4.x/embedding-jetty.html
        ServletHandler handler = new ServletHandler();
        healthCheckServer.setHandler(handler);
        // register a servlet for checking on the health of the entire apisynthesis process
        // only allow requests on port _httpHeartbeatListenPort
        handler.addServletWithMapping(ApiSynthesisHealthCheckServlet.class, "/apisynthesishealth");
    }
    /*
         * Set the server id for response headers.
         */
    String serverId = UUID.randomUUID().toString();
    ServerIdHttpServlet.setServerId(serverId);
    _logger.info("Server id is: " + serverId);
    /*
         * Start the HTTP servers.
         */
    try {
        // returns immediately
        healthCheckServer.start();
        _logger.info("Started HTTP heartbeat server on port " + _httpHeartbeatListenPort);
        // returns immediately
        apiSynthServer.start();
        _logger.info("Started HTTP synth server on port " + _httpRequestListenPort);
    } catch (Throwable e) {
        _logger.debug("exiting");
        throw new StartErrorException(e);
    }
    _logger.debug("exiting");
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ApiSynthesisHealthCheckServlet(edu.rice.cs.caper.bayou.application.api_synthesis_server.servlet.ApiSynthesisHealthCheckServlet) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ApiSynthesisServlet(edu.rice.cs.caper.bayou.application.api_synthesis_server.servlet.ApiSynthesisServlet) ApiSynthesisResultQualityFeedbackServlet(edu.rice.cs.caper.bayou.application.api_synthesis_server.servlet.ApiSynthesisResultQualityFeedbackServlet) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool)

Example 7 with ExecutorThreadPool

use of org.eclipse.jetty.util.thread.ExecutorThreadPool in project jo-client-platform by jo-source.

the class CapServerStarter method startServer.

public static void startServer(final String brokerId, final int port, final MessageServletConfig config) throws Exception {
    Assert.paramNotNull(brokerId, "brokerId");
    final Server server = new Server(port);
    final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(32, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), DaemonThreadFactory.multi(CapServerStarter.class.getName() + ".ServletExecutor"));
    server.setThreadPool(new ExecutorThreadPool(threadPoolExecutor));
    final ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS);
    final ServletHolder servletHolder = new ServletHolder(new SecurityRemotingServlet(brokerId));
    setConfigParameters(servletHolder, config);
    root.addServlet(servletHolder, "/");
    root.addFilter(new FilterHolder(new BasicAuthenticationFilter()), "/", FilterMapping.DEFAULT);
    addServletFilters(root, config);
    server.setHandler(root);
    server.start();
    server.join();
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) BasicAuthenticationFilter(org.jowidgets.security.impl.http.server.BasicAuthenticationFilter) ExecutorThreadPool(org.eclipse.jetty.util.thread.ExecutorThreadPool) SecurityRemotingServlet(org.jowidgets.security.impl.http.server.SecurityRemotingServlet) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ExecutorThreadPool (org.eclipse.jetty.util.thread.ExecutorThreadPool)7 Server (org.eclipse.jetty.server.Server)6 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)5 ServerConnector (org.eclipse.jetty.server.ServerConnector)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 DispatcherType (javax.servlet.DispatcherType)2 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)2 HiveAuthFactory (org.apache.hive.service.auth.HiveAuthFactory)2 ThreadFactoryWithGarbageCleanup (org.apache.hive.service.server.ThreadFactoryWithGarbageCleanup)2 TProcessor (org.apache.thrift.TProcessor)2 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)2 TServlet (org.apache.thrift.server.TServlet)2 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 GzipHandler (org.eclipse.jetty.server.handler.gzip.GzipHandler)2 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)2 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)2 AnnisRunnerException (annis.AnnisRunnerException)1 MultipleIniWebEnvironment (annis.security.MultipleIniWebEnvironment)1