Search in sources :

Example 1 with NamedThreadFactory

use of io.micrometer.core.instrument.util.NamedThreadFactory in project zipkin by openzipkin.

the class ZipkinElasticsearchStorageConfiguration method dynamicCredentialsScheduledExecutorService.

@Bean(destroyMethod = "shutdown")
@Qualifier(QUALIFIER)
@Conditional(DynamicRefreshRequired.class)
ScheduledExecutorService dynamicCredentialsScheduledExecutorService(@Value("${" + CREDENTIALS_FILE + "}") String credentialsFile, @Value("${" + CREDENTIALS_REFRESH_INTERVAL + "}") Integer credentialsRefreshInterval, @Qualifier(QUALIFIER) BasicCredentials basicCredentials) throws IOException {
    ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("zipkin-load-es-credentials"));
    DynamicCredentialsFileLoader credentialsFileLoader = new DynamicCredentialsFileLoader(basicCredentials, credentialsFile);
    credentialsFileLoader.updateCredentialsFromProperties();
    ScheduledFuture<?> future = ses.scheduleAtFixedRate(credentialsFileLoader, 0, credentialsRefreshInterval, TimeUnit.SECONDS);
    if (future.isDone())
        throw new RuntimeException("credential refresh thread didn't start");
    return ses;
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(io.micrometer.core.instrument.util.NamedThreadFactory) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Conditional(org.springframework.context.annotation.Conditional) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

NamedThreadFactory (io.micrometer.core.instrument.util.NamedThreadFactory)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Conditional (org.springframework.context.annotation.Conditional)1