@Override public void onRun(C configuration, Environment environment, DropwizardTestSupport<C> rule) throws Exception { environment.lifecycle().manage(managed); } });
public ScheduledExecutorService build() { final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.poolSize, this.threadFactory, this.handler); executor.setRemoveOnCancelPolicy(this.removeOnCancel); this.environment.manage(new ExecutorServiceManager(executor, this.shutdownTime, this.nameFormat)); return executor; } }
public ExecutorService build() { if (corePoolSize != maximumPoolSize && maximumPoolSize > 1 && !isBoundedQueue()) { log.warn("Parameter 'maximumPoolSize' is conflicting with unbounded work queues"); } final ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime.getQuantity(), keepAliveTime.getUnit(), workQueue, threadFactory, handler); executor.allowCoreThreadTimeOut(allowCoreThreadTimeOut); environment.manage(new ExecutorServiceManager(executor, shutdownTime, nameFormat)); return executor; }
/** * Configures the given lifecycle with the {@link com.codahale.metrics.ScheduledReporter * reporters} configured for the given registry. * <p /> * The reporters are tied in to the given lifecycle, such that their {@link #getFrequency() * frequency} for reporting metrics begins when the lifecycle {@link * io.dropwizard.lifecycle.Managed#start() starts}, and stops when the lifecycle * {@link io.dropwizard.lifecycle.Managed#stop() stops}. * * @param environment the lifecycle to manage the reporters. * @param registry the metric registry to report metrics from. */ public void configure(LifecycleEnvironment environment, MetricRegistry registry) { for (ReporterFactory reporter : reporters) { try { final ScheduledReporterManager manager = new ScheduledReporterManager(reporter.build(registry), reporter.getFrequency().orElseGet(this::getFrequency), reportOnStop); environment.manage(manager); } catch (Exception e) { LOGGER.warn("Failed to create reporter, metrics may not be properly reported.", e); } } }
/** * 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; }
lifecycle.manage(new ManagedPubSub(pubsub));
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; }
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);
environment.lifecycle().manage(new Managed() { @Override public void start() throws Exception {
environment.lifecycle().manage(dataSource);
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)); }
@Override public void onRun(C configuration, Environment environment, DropwizardTestSupport<C> rule) throws Exception { environment.lifecycle().manage(managed); } });
@Override public <T extends Managed> T manage(T managed) { _environment.lifecycle().manage(managed); return managed; }
public ScheduledExecutorService build() { final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.poolSize, this.threadFactory, this.handler); executor.setRemoveOnCancelPolicy(this.removeOnCancel); this.environment.manage(new ExecutorServiceManager(executor, this.shutdownTime, this.nameFormat)); return executor; } }
/** * Detect {@link Managed} components. */ private void detectManaged(final Environment environment) { for (BeanEntry<Annotation, Managed> entry : locate(Managed.class)) { Managed component = entry.getValue(); environment.lifecycle().manage(component); log.debug("Added managed: {}", component); } }