Search in sources :

Example 1 with ElideStandaloneSubscriptionSettings

use of com.yahoo.elide.standalone.config.ElideStandaloneSubscriptionSettings in project elide by yahoo.

the class ElideStandalone method start.

/**
 * Start the Elide service.
 *
 * @param block - Whether or not to wait for the server to shutdown.
 * @throws Exception Exception thrown
 */
public void start(boolean block) throws Exception {
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    log.info("Starting jetty server on port: {}", elideStandaloneSettings.getPort());
    jettyServer = new Server(elideStandaloneSettings.getPort());
    jettyServer.setHandler(context);
    context.setAttribute(ELIDE_STANDALONE_SETTINGS_ATTR, elideStandaloneSettings);
    if (elideStandaloneSettings.getAsyncProperties().enabled()) {
        Integer threadPoolSize = elideStandaloneSettings.getAsyncProperties().getThreadSize() == null ? AsyncExecutorService.DEFAULT_THREAD_POOL_SIZE : elideStandaloneSettings.getAsyncProperties().getThreadSize();
        context.setAttribute(ASYNC_EXECUTOR_ATTR, Executors.newFixedThreadPool(threadPoolSize));
        context.setAttribute(ASYNC_UPDATER_ATTR, Executors.newFixedThreadPool(threadPoolSize));
    }
    if (elideStandaloneSettings.enableJSONAPI()) {
        ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, elideStandaloneSettings.getJsonApiPathSpec());
        jerseyServlet.setInitOrder(0);
        jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.yahoo.elide.jsonapi.resources");
        jerseyServlet.setInitParameter("javax.ws.rs.Application", ElideResourceConfig.class.getCanonicalName());
    }
    if (elideStandaloneSettings.enableGraphQL()) {
        ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, elideStandaloneSettings.getGraphQLApiPathSpec());
        jerseyServlet.setInitOrder(0);
        jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.yahoo.elide.graphql");
        jerseyServlet.setInitParameter("javax.ws.rs.Application", ElideResourceConfig.class.getCanonicalName());
    }
    ElideStandaloneSubscriptionSettings subscriptionSettings = elideStandaloneSettings.getSubscriptionProperties();
    if (elideStandaloneSettings.enableGraphQL() && subscriptionSettings.enabled()) {
        // GraphQL subscription endpoint
        ServerContainer container = WebSocketServerContainerInitializer.configureContext(context);
        ServerEndpointConfig subscriptionEndpoint = subscriptionSettings.serverEndpointConfig(elideStandaloneSettings);
        container.addEndpoint(subscriptionEndpoint);
    }
    if (elideStandaloneSettings.getAsyncProperties().enableExport()) {
        ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, elideStandaloneSettings.getAsyncProperties().getExportApiPathSpec());
        jerseyServlet.setInitOrder(0);
        jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.yahoo.elide.async.resources");
        jerseyServlet.setInitParameter("javax.ws.rs.Application", ElideResourceConfig.class.getCanonicalName());
    }
    if (elideStandaloneSettings.enableServiceMonitoring()) {
        FilterHolder instrumentedFilterHolder = new FilterHolder(InstrumentedFilter.class);
        instrumentedFilterHolder.setName("instrumentedFilter");
        instrumentedFilterHolder.setAsyncSupported(true);
        context.addFilter(instrumentedFilterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
        context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, ElideResourceConfig.getHealthCheckRegistry());
        context.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, ElideResourceConfig.getMetricRegistry());
        context.setAttribute(MetricsServlet.METRICS_REGISTRY, ElideResourceConfig.getMetricRegistry());
        context.addServlet(AdminServlet.class, "/stats/*");
    }
    if (elideStandaloneSettings.enableSwagger()) {
        ServletHolder jerseyServlet = context.addServlet(ServletContainer.class, elideStandaloneSettings.getSwaggerPathSpec());
        jerseyServlet.setInitOrder(0);
        jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.yahoo.elide.swagger.resources");
        jerseyServlet.setInitParameter("javax.ws.rs.Application", ElideResourceConfig.class.getCanonicalName());
    }
    elideStandaloneSettings.updateServletContextHandler(context);
    try {
        jettyServer.start();
        log.info("Jetty started!");
        if (block) {
            jettyServer.join();
        }
    } catch (Exception e) {
        log.error("Unexpected exception caught: {}", e.getMessage(), e);
        throw e;
    } finally {
        if (block) {
            jettyServer.destroy();
        }
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ElideResourceConfig(com.yahoo.elide.standalone.config.ElideResourceConfig) ElideStandaloneSubscriptionSettings(com.yahoo.elide.standalone.config.ElideStandaloneSubscriptionSettings) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServerContainer(javax.websocket.server.ServerContainer)

Example 2 with ElideStandaloneSubscriptionSettings

use of com.yahoo.elide.standalone.config.ElideStandaloneSubscriptionSettings in project elide by yahoo.

the class ElideStandaloneSubscriptionTest method init.

@BeforeAll
public void init() throws Exception {
    settings = new ElideStandaloneTestSettings() {

        @Override
        public ElideStandaloneSubscriptionSettings getSubscriptionProperties() {
            return new ElideStandaloneSubscriptionSettings() {

                @Override
                public boolean enabled() {
                    return true;
                }

                @Override
                public ConnectionFactory getConnectionFactory() {
                    return new ActiveMQConnectionFactory("vm://0");
                }
            };
        }
    };
    elide = new ElideStandalone(settings);
    elide.start(false);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ElideStandaloneSubscriptionSettings(com.yahoo.elide.standalone.config.ElideStandaloneSubscriptionSettings) ElideStandalone(com.yahoo.elide.standalone.ElideStandalone) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ElideStandaloneSubscriptionSettings (com.yahoo.elide.standalone.config.ElideStandaloneSubscriptionSettings)2 ElideStandalone (com.yahoo.elide.standalone.ElideStandalone)1 ElideResourceConfig (com.yahoo.elide.standalone.config.ElideResourceConfig)1 ConnectionFactory (javax.jms.ConnectionFactory)1 ServerContainer (javax.websocket.server.ServerContainer)1 ServerEndpointConfig (javax.websocket.server.ServerEndpointConfig)1 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)1 Server (org.eclipse.jetty.server.Server)1 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1