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();
}
}
}
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);
}
Aggregations