diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-06-04 14:07:02 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2020-06-04 14:11:59 +0200 |
commit | 8d6e96229906157b3ce3ee7b5d4732431af9f126 (patch) | |
tree | e9a67e7183042772ee44c1690bcd44af4b7120ec /config-model/src/main/java | |
parent | d4ab7939241495a43e9ed170a99901b28602997f (diff) |
Add component definition for ThreadPoolProvider with custom config
Diffstat (limited to 'config-model/src/main/java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java new file mode 100644 index 00000000000..0c79239bdcd --- /dev/null +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ThreadPoolExecutorComponent.java @@ -0,0 +1,70 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.model.container; + +import com.yahoo.container.bundle.BundleInstantiationSpecification; +import com.yahoo.container.handler.ThreadPoolProvider; +import com.yahoo.container.handler.ThreadpoolConfig; +import com.yahoo.osgi.provider.model.ComponentModel; +import com.yahoo.vespa.model.container.component.SimpleComponent; + +import java.time.Duration; + +/** + * Component definition for a {@link java.util.concurrent.Executor} using {@link ThreadPoolProvider}. + * + * @author bjorncs + */ +public class ThreadPoolExecutorComponent extends SimpleComponent implements ThreadpoolConfig.Producer { + + private final String name; + private final Integer maxPoolSize; + private final Integer corePoolSize; + private final Duration keepAliveTime; + private final Integer queueSize; + private final Duration maxThreadExecutionTime; + + private ThreadPoolExecutorComponent(Builder builder) { + super(new ComponentModel( + BundleInstantiationSpecification.getFromStrings( + "threadpool-provider@" + builder.name, + ThreadPoolProvider.class.getName(), + null))); + this.name = builder.name; + this.maxPoolSize = builder.maxPoolSize; + this.corePoolSize = builder.corePoolSize; + this.keepAliveTime = builder.keepAliveTime; + this.queueSize = builder.queueSize; + this.maxThreadExecutionTime = builder.maxThreadExecutionTime; + } + + @Override + public void getConfig(ThreadpoolConfig.Builder builder) { + builder.name(this.name); + if (maxPoolSize != null) builder.maxthreads(maxPoolSize); + if (corePoolSize != null) builder.corePoolSize(corePoolSize); + if (keepAliveTime != null) builder.keepAliveTime(keepAliveTime.toMillis() / 1000D); + if (queueSize != null) builder.queueSize(queueSize); + if (maxThreadExecutionTime != null) builder.maxThreadExecutionTimeSeconds((int)maxThreadExecutionTime.toMillis() / 1000); + } + + public static class Builder { + + private final String name; + private Integer maxPoolSize; + private Integer corePoolSize; + private Duration keepAliveTime; + private Integer queueSize; + private Duration maxThreadExecutionTime; + + public Builder(String name) { this.name = name; } + + Builder maxPoolSize(int size) { this.maxPoolSize = size; return this; } + Builder corePoolSize(int size) { this.corePoolSize = size; return this; } + Builder keepAliveTime(Duration time) { this.keepAliveTime = time; return this; } + Builder queueSize(int size) { this.queueSize = size; return this; } + Builder maxThreadExecutionTime(Duration time) { this.maxThreadExecutionTime = time; return this; } + + ThreadPoolExecutorComponent build() { return new ThreadPoolExecutorComponent(this); } + + } +} |