2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.config;
10 import static java.util.Objects.requireNonNull;
13 import java.util.concurrent.TimeUnit;
14 import javax.annotation.PreDestroy;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import org.opendaylight.controller.config.threadpool.ThreadPool;
18 import org.opendaylight.controller.config.threadpool.util.FlexibleThreadPoolWrapper;
19 import org.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Deactivate;
24 @Component(factory = GlobalNetconfProcessingExecutor.FACTORY_NAME, service = ThreadPool.class)
25 public final class GlobalNetconfProcessingExecutor extends FlexibleThreadPoolWrapper {
26 public static final String OSGI_TYPE = "global-netconf-processing-executor";
27 public static final int DEFAULT_MIN_THREAD_COUNT = 1;
28 public static final int DEFAULT_MAX_THREAD_COUNT = 4;
29 public static final long DEFAULT_KEEPALIVE_MILLIS = 600000;
31 // OSGi DS Component Factory name
32 static final String FACTORY_NAME = "org.opendaylight.netconf.config.GlobalNetconfProcessingExecutor";
34 private static final String PROP_KEEPALIVE = ".keepAlive";
35 private static final String PROP_MIN_THREAD_COUNT = ".minThreadCount";
36 private static final String PROP_MAX_THREAD_COUNT = ".maxThreadCount";
37 private static final String PROP_THREAD_FACTORY = ".threadFactory";
39 public GlobalNetconfProcessingExecutor(final GlobalNetconfThreadFactory threadFactory, final int minThreadCount,
40 final int maxThreadCount, final long keepAliveMillis) {
41 super(minThreadCount, maxThreadCount, keepAliveMillis, TimeUnit.MILLISECONDS, threadFactory);
45 public GlobalNetconfProcessingExecutor(final GlobalNetconfThreadFactory threadFactory) {
46 this(threadFactory, DEFAULT_MIN_THREAD_COUNT, DEFAULT_MAX_THREAD_COUNT, DEFAULT_KEEPALIVE_MILLIS);
50 public GlobalNetconfProcessingExecutor(final Map<String, ?> properties) {
51 this(GlobalNetconfConfiguration.extractProp(properties, PROP_THREAD_FACTORY, GlobalNetconfThreadFactory.class),
52 GlobalNetconfConfiguration.extractProp(properties, PROP_MIN_THREAD_COUNT, Integer.class),
53 GlobalNetconfConfiguration.extractProp(properties, PROP_MAX_THREAD_COUNT, Integer.class),
54 GlobalNetconfConfiguration.extractProp(properties, PROP_KEEPALIVE, Long.class));
64 static Map<String, ?> props(final GlobalNetconfThreadFactory threadFactory, final Configuration configuration) {
67 PROP_THREAD_FACTORY, requireNonNull(threadFactory),
68 PROP_KEEPALIVE, configuration.keep$_$alive$_$millis$_$flexible$_$thread$_$pool(),
69 PROP_MIN_THREAD_COUNT, configuration.min$_$thread$_$count$_$flexible$_$thread$_$pool(),
70 PROP_MAX_THREAD_COUNT, configuration.max$_$thread$_$count$_$flexible$_$thread$_$pool());