Search in sources :

Example 1 with InstrumentedScheduledExecutorService

use of com.codahale.metrics.InstrumentedScheduledExecutorService in project dropwizard by dropwizard.

the class DefaultHealthFactory method createScheduledExecutorForHealthChecks.

private ScheduledExecutorService createScheduledExecutorForHealthChecks(final int numberOfScheduledHealthChecks, final MetricRegistry metrics, final LifecycleEnvironment lifecycle, final String fullName) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(fullName + "-%d").setDaemon(true).setUncaughtExceptionHandler((t, e) -> LOGGER.error("Thread={} died due to uncaught exception", t, e)).build();
    final InstrumentedThreadFactory instrumentedThreadFactory = new InstrumentedThreadFactory(threadFactory, metrics);
    final ScheduledExecutorService scheduledExecutorService = lifecycle.scheduledExecutorService(fullName + "-scheduled-executor", instrumentedThreadFactory).threads(numberOfScheduledHealthChecks).build();
    return new InstrumentedScheduledExecutorService(scheduledExecutorService, metrics);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ServletHealthResponderFactory(io.dropwizard.health.response.ServletHealthResponderFactory) Size(javax.validation.constraints.Size) InstrumentedThreadFactory(com.codahale.metrics.InstrumentedThreadFactory) LoggerFactory(org.slf4j.LoggerFactory) HealthResponseProviderFactory(io.dropwizard.health.response.HealthResponseProviderFactory) Duration(io.dropwizard.util.Duration) Collections.singletonList(java.util.Collections.singletonList) Valid(javax.validation.Valid) JsonTypeName(com.fasterxml.jackson.annotation.JsonTypeName) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ServletEnvironment(io.dropwizard.jetty.setup.ServletEnvironment) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThreadFactory(java.util.concurrent.ThreadFactory) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HealthResponseProvider(io.dropwizard.health.response.HealthResponseProvider) NotNull(javax.validation.constraints.NotNull) HealthResponderFactory(io.dropwizard.health.response.HealthResponderFactory) List(java.util.List) JsonHealthResponseProviderFactory(io.dropwizard.health.response.JsonHealthResponseProviderFactory) InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) Collections(java.util.Collections) InstrumentedThreadFactory(com.codahale.metrics.InstrumentedThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) InstrumentedThreadFactory(com.codahale.metrics.InstrumentedThreadFactory) InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 2 with InstrumentedScheduledExecutorService

use of com.codahale.metrics.InstrumentedScheduledExecutorService in project atlasdb by palantir.

the class AsyncTimeLockServicesCreator method createRawAsyncTimelockService.

private static AsyncTimelockService createRawAsyncTimelockService(String client, Supplier<ManagedTimestampService> timestampServiceSupplier) {
    ScheduledExecutorService reaperExecutor = new InstrumentedScheduledExecutorService(PTExecutors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("async-lock-reaper-" + client + "-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), "async-lock-reaper");
    ScheduledExecutorService timeoutExecutor = new InstrumentedScheduledExecutorService(PTExecutors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("async-lock-timeouts-" + client + "-%d").setDaemon(true).build()), AtlasDbMetrics.getMetricRegistry(), "async-lock-timeouts");
    return new AsyncTimelockServiceImpl(AsyncLockService.createDefault(reaperExecutor, timeoutExecutor), timestampServiceSupplier.get());
}
Also used : InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) AsyncTimelockServiceImpl(com.palantir.atlasdb.timelock.AsyncTimelockServiceImpl)

Aggregations

InstrumentedScheduledExecutorService (com.codahale.metrics.InstrumentedScheduledExecutorService)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 InstrumentedThreadFactory (com.codahale.metrics.InstrumentedThreadFactory)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonTypeName (com.fasterxml.jackson.annotation.JsonTypeName)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AsyncTimelockServiceImpl (com.palantir.atlasdb.timelock.AsyncTimelockServiceImpl)1 HealthResponderFactory (io.dropwizard.health.response.HealthResponderFactory)1 HealthResponseProvider (io.dropwizard.health.response.HealthResponseProvider)1 HealthResponseProviderFactory (io.dropwizard.health.response.HealthResponseProviderFactory)1 JsonHealthResponseProviderFactory (io.dropwizard.health.response.JsonHealthResponseProviderFactory)1 ServletHealthResponderFactory (io.dropwizard.health.response.ServletHealthResponderFactory)1 JerseyEnvironment (io.dropwizard.jersey.setup.JerseyEnvironment)1 ServletEnvironment (io.dropwizard.jetty.setup.ServletEnvironment)1 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)1 Duration (io.dropwizard.util.Duration)1 Collections (java.util.Collections)1