io.camunda.zeebe.spring.client.configuration.ExecutorServiceConfiguration Maven / Gradle / Ivy
/*
* Copyright © 2017 camunda services GmbH ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.zeebe.spring.client.configuration;
import static io.camunda.zeebe.spring.client.configuration.PropertyUtil.getOrLegacyOrDefault;
import static io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties.DEFAULT;
import io.camunda.zeebe.spring.client.jobhandling.ZeebeClientExecutorService;
import io.camunda.zeebe.spring.client.properties.CamundaClientProperties;
import io.camunda.zeebe.spring.client.properties.ZeebeClientConfigurationProperties;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;
import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnMissingBean(ZeebeClientExecutorService.class)
public class ExecutorServiceConfiguration {
private final ZeebeClientConfigurationProperties configurationProperties;
private final CamundaClientProperties camundaClientProperties;
public ExecutorServiceConfiguration(
final ZeebeClientConfigurationProperties configurationProperties,
final CamundaClientProperties camundaClientProperties) {
this.configurationProperties = configurationProperties;
this.camundaClientProperties = camundaClientProperties;
}
@Bean
public ZeebeClientExecutorService zeebeClientThreadPool(
@Autowired(required = false) final MeterRegistry meterRegistry) {
final ScheduledExecutorService threadPool =
Executors.newScheduledThreadPool(
getOrLegacyOrDefault(
"NumJobWorkerExecutionThreads",
() -> camundaClientProperties.getZeebe().getExecutionThreads(),
configurationProperties::getNumJobWorkerExecutionThreads,
DEFAULT.getNumJobWorkerExecutionThreads(),
null));
if (meterRegistry != null) {
final MeterBinder threadPoolMetrics =
new ExecutorServiceMetrics(
threadPool, "zeebe_client_thread_pool", Collections.emptyList());
threadPoolMetrics.bindTo(meterRegistry);
}
return new ZeebeClientExecutorService(threadPool, true);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy