Search in sources :

Example 1 with RAPServlet

use of com.linkedin.r2.transport.http.server.RAPServlet in project rest.li by linkedin.

the class RestliServlet method buildR2ServletFromServletParams.

private AbstractR2Servlet buildR2ServletFromServletParams(ServletConfig servletConfig) {
    ResourceFactory resourceFactory = new PrototypeResourceFactory();
    RestLiConfig config = new RestLiConfig();
    config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig));
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(getParseqThreadPoolSize(servletConfig));
    Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build();
    final RestLiServer restLiServer = new RestLiServer(config, resourceFactory, engine);
    DelegatingTransportDispatcher dispatcher = new DelegatingTransportDispatcher(restLiServer, restLiServer);
    boolean useAsync = getUseAsync(servletConfig);
    long asyncTimeOut = getAsyncTimeout(servletConfig);
    if (useAsync && servletConfig.getServletContext().getMajorVersion() < 3) {
        throw new IllegalArgumentException("This servlet is configured with useAsync=true, but the current servlet " + "context does not support the required Servlet API 3.0.");
    }
    if (!useAsync) {
        log.info("Initializing Rest.li with a thread based request handling.  Set useAsync=true on a Servlet API 3.0 container to enable Rest.li's async servlet.");
        return new RAPServlet(dispatcher);
    } else {
        log.info("Initializing Rest.li with an async request handling enabled.");
        return new AsyncR2Servlet(dispatcher, asyncTimeOut);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RAPServlet(com.linkedin.r2.transport.http.server.RAPServlet) ResourceFactory(com.linkedin.restli.server.resources.ResourceFactory) PrototypeResourceFactory(com.linkedin.restli.server.resources.PrototypeResourceFactory) AsyncR2Servlet(com.linkedin.r2.transport.http.server.AsyncR2Servlet) PrototypeResourceFactory(com.linkedin.restli.server.resources.PrototypeResourceFactory) EngineBuilder(com.linkedin.parseq.EngineBuilder) Engine(com.linkedin.parseq.Engine)

Example 2 with RAPServlet

use of com.linkedin.r2.transport.http.server.RAPServlet in project rest.li by linkedin.

the class HttpServerFactory method createRAPServer.

public HttpServer createRAPServer(int port, TransportDispatcher transportDispatcher, int timeout, boolean restOverStream) {
    final TransportDispatcher filterDispatcher = new FilterChainDispatcher(transportDispatcher, _filters);
    HttpServlet httpServlet = restOverStream ? new RAPStreamServlet(filterDispatcher, timeout, DEFAULT_LOG_SERVLET_EXCEPTIONS) : new RAPServlet(filterDispatcher);
    return new HttpJettyServer(port, httpServlet);
}
Also used : FilterChainDispatcher(com.linkedin.r2.filter.transport.FilterChainDispatcher) HttpServlet(javax.servlet.http.HttpServlet) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)

Aggregations

Engine (com.linkedin.parseq.Engine)1 EngineBuilder (com.linkedin.parseq.EngineBuilder)1 FilterChainDispatcher (com.linkedin.r2.filter.transport.FilterChainDispatcher)1 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)1 AsyncR2Servlet (com.linkedin.r2.transport.http.server.AsyncR2Servlet)1 RAPServlet (com.linkedin.r2.transport.http.server.RAPServlet)1 PrototypeResourceFactory (com.linkedin.restli.server.resources.PrototypeResourceFactory)1 ResourceFactory (com.linkedin.restli.server.resources.ResourceFactory)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 HttpServlet (javax.servlet.http.HttpServlet)1