@Override public void onRun(C configuration, Environment environment, DropwizardTestSupport<C> rule) throws Exception { environment.lifecycle().manage(managed); } });
@Override public void run(C configuration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(server -> jettyServer = server); DropwizardTestSupport.this.configuration = configuration; DropwizardTestSupport.this.environment = environment; super.run(configuration, environment); for (ServiceListener<C> listener : listeners) { try { listener.onRun(configuration, environment, DropwizardTestSupport.this); } catch (Exception ex) { throw new RuntimeException("Error running app rule start listener", ex); } } } };
/** * Builds the {@link HttpClient}. * * @param name * @return an {@link CloseableHttpClient} */ public CloseableHttpClient build(String name) { final CloseableHttpClient client = buildWithDefaultRequestConfiguration(name).getClient(); // If the environment is present, we tie the client with the server lifecycle if (environment != null) { environment.lifecycle().manage(new Managed() { @Override public void start() throws Exception { } @Override public void stop() throws Exception { client.close(); } }); } return client; }
final LifecycleEnvironment lifecycle = environment.lifecycle();
/** * Builds the {@link Client} instance. * * @return a fully-configured {@link Client} */ public Client build(String name) { if ((environment == null) && ((executorService == null) || (objectMapper == null))) { throw new IllegalStateException("Must have either an environment or both " + "an executor service and an object mapper"); } if (executorService == null) { // Create an ExecutorService based on the provided // configuration. The DisposableExecutorService decorator // is used to ensure that the service is shut down if the // Jersey client disposes of it. executorService = requireNonNull(environment).lifecycle() .executorService("jersey-client-" + name + "-%d") .minThreads(configuration.getMinThreads()) .maxThreads(configuration.getMaxThreads()) .workQueue(new ArrayBlockingQueue<>(configuration.getWorkQueueSize())) .build(); } if (objectMapper == null) { objectMapper = requireNonNull(environment).getObjectMapper(); } if (environment != null) { validator = environment.getValidator(); } return build(name, executorService, objectMapper, validator); }
public SessionFactory build(HibernateBundle<?> bundle, Environment environment, PooledDataSourceFactory dbConfig, ManagedDataSource dataSource, List<Class<?>> entities) { final ConnectionProvider provider = buildConnectionProvider(dataSource, dbConfig.getProperties()); final SessionFactory factory = buildSessionFactory(bundle, dbConfig, provider, dbConfig.getProperties(), entities); final SessionFactoryManager managedFactory = new SessionFactoryManager(factory, dataSource); environment.lifecycle().manage(managedFactory); return factory; }
this.healthCheckExecutorService = this.lifecycle().executorService("TimeBoundHealthCheck-pool-%d") .workQueue(new ArrayBlockingQueue<>(1)) .minThreads(1)
private Client build(String name, ExecutorService threadPool, ObjectMapper objectMapper, Validator validator) { if (!configuration.isGzipEnabled()) { apacheHttpClientBuilder.disableContentCompression(true); } final Client client = ClientBuilder.newClient(buildConfig(name, threadPool, objectMapper, validator)); client.register(new JerseyIgnoreRequestUserAgentHeaderFilter()); // Tie the client to server lifecycle if (environment != null) { environment.lifecycle().manage(new Managed() { @Override public void start() throws Exception { } @Override public void stop() throws Exception { client.close(); } }); } if (configuration.isGzipEnabled()) { client.register(new GZipDecoder()); client.register(new ConfiguredGZipEncoder(configuration.isGzipEnabledForRequests())); } return client; }
environment.lifecycle().manage(new ManagedStatsdReporter(config.getStatsdHostPort(), metricsRegistry)); attributesSupplier); environment.lifecycle().manage(reporter); final DockerHealthChecker dockerHealthChecker = new DockerHealthChecker( metrics.getSupervisorMetrics(), TimeUnit.SECONDS, 30); environment.lifecycle().manage(dockerHealthChecker); environment.lifecycle().manage(this); this.server = null; environment.lifecycle().manage(this);
@Override protected void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception { final Environment environment = new Environment(bootstrap.getApplication().getName(), bootstrap.getObjectMapper(), bootstrap.getValidatorFactory(), bootstrap.getMetricRegistry(), bootstrap.getClassLoader(), bootstrap.getHealthCheckRegistry()); configuration.getMetricsFactory().configure(environment.lifecycle(), bootstrap.getMetricRegistry()); configuration.getServerFactory().configure(environment); bootstrap.run(configuration, environment); application.run(configuration, environment); run(environment, namespace, configuration); }
environment.lifecycle().manage(new Managed() { @Override public void start() throws Exception {
environment.lifecycle().manage(dataSource);
final Server server = buildServer(environment.lifecycle(), threadPool);
@Override public Server build(Environment environment) { printBanner(environment.getName()); final ThreadPool threadPool = createThreadPool(environment.metrics()); final Server server = buildServer(environment.lifecycle(), threadPool); final Handler applicationHandler = createAppServlet(server, environment.jersey(), environment.getObjectMapper(), environment.getValidator(), environment.getApplicationContext(), environment.getJerseyServletContainer(), environment.metrics()); final Handler adminHandler = createAdminServlet(server, environment.getAdminContext(), environment.metrics(), environment.healthChecks()); final RoutingHandler routingHandler = buildRoutingHandler(environment.metrics(), server, applicationHandler, adminHandler); final Handler gzipHandler = buildGzipHandler(routingHandler); server.setHandler(addStatsHandler(addRequestLog(server, gzipHandler, environment.getName()))); return server; }
environment.lifecycle().manage(dataSource);
private void runRegularGraphHopper(CmdArgs configuration, Environment environment) { final GraphHopperManaged graphHopperManaged = new GraphHopperManaged(configuration, environment.getObjectMapper()); environment.lifecycle().manage(graphHopperManaged); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bind(configuration).to(CmdArgs.class); bind(graphHopperManaged).to(GraphHopperManaged.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopper.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopperAPI.class); bindFactory(HasElevation.class).to(Boolean.class).named("hasElevation"); bindFactory(LocationIndexFactory.class).to(LocationIndex.class); bindFactory(TranslationMapFactory.class).to(TranslationMap.class); bindFactory(EncodingManagerFactory.class).to(EncodingManager.class); bindFactory(GraphHopperStorageFactory.class).to(GraphHopperStorage.class); bindFactory(RasterHullBuilderFactory.class).to(DelaunayTriangulationIsolineBuilder.class); } }); if (configuration.getBool("web.change_graph.enabled", false)) { environment.jersey().register(ChangeGraphResource.class); } environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); }
@Override public void run(BithubServerConfiguration config, Environment environment) throws Exception { String githubUser = config.getGithubConfiguration().getUser(); String githubToken = config.getGithubConfiguration().getToken(); String githubWebhookUser = config.getGithubConfiguration().getWebhookConfiguration().getUsername(); String githubWebhookPwd = config.getGithubConfiguration().getWebhookConfiguration().getPassword(); List<RepositoryConfiguration> githubRepositories = config.getGithubConfiguration().getRepositories(); BigDecimal payoutRate = config.getBithubConfiguration().getPayoutRate(); String organizationName = config.getOrganizationConfiguration().getName(); String donationUrl = config.getOrganizationConfiguration().getDonationUrl().toExternalForm(); String coinbaseApiKey = config.getCoinbaseConfiguration().getApiKey(); String coinbaseApiSecret = config.getCoinbaseConfiguration().getApiSecret(); GithubClient githubClient = new GithubClient(githubUser, githubToken); CoinbaseClient coinbaseClient = new CoinbaseClient(coinbaseApiKey, coinbaseApiSecret); CacheManager cacheManager = new CacheManager(coinbaseClient, githubClient, githubRepositories, payoutRate); environment.servlets().addFilter("CORS", CrossOriginFilter.class) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); environment.lifecycle().manage(cacheManager); environment.jersey().register(new GithubController(githubRepositories, githubClient, coinbaseClient, payoutRate)); environment.jersey().register(new StatusController(cacheManager, githubRepositories)); environment.jersey().register(new DashboardController(organizationName, donationUrl, cacheManager)); environment.jersey().register(new IOExceptionMapper()); environment.jersey().register(new UnauthorizedHookExceptionMapper()); environment.jersey().register(new BasicAuthProvider<>(new GithubWebhookAuthenticator(githubWebhookUser, githubWebhookPwd), GithubWebhookAuthenticator.REALM)); }
public void start() throws Exception { // Start all the managed instances in dropwizard. Set<LifeCycle> managedObjects = ImmutableSet.copyOf(environment.lifecycle().getManagedObjects()); for (LifeCycle managed : managedObjects) { managed.start(); } }