Fix nullability checks in PropertyEntity class
[netconf.git] / netconf / netconf-config / src / main / java / org / opendaylight / netconf / config / GlobalNetconfSshScheduledExecutor.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.config;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Map;
13 import javax.annotation.PreDestroy;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
17 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
21
22 @Singleton
23 @Component(factory = GlobalNetconfSshScheduledExecutor.FACTORY_NAME, service = ScheduledThreadPool.class)
24 public final class GlobalNetconfSshScheduledExecutor extends ScheduledThreadPoolWrapper {
25     public static final String OSGI_TYPE = "global-netconf-ssh-scheduled-executor";
26     public static final int DEFAULT_MAX_THREAD_COUNT = 8;
27
28     // OSGi DS Component Factory name
29     static final String FACTORY_NAME = "org.opendaylight.netconf.config.GlobalNetconfSshScheduledExecutor";
30
31     private static final String PROP_MAX_THREAD_COUNT = ".maxThreadCount";
32     private static final String PROP_THREAD_FACTORY = ".threadFactory";
33
34     public GlobalNetconfSshScheduledExecutor(final GlobalNetconfThreadFactory threadFactory, final int maxThreadCount) {
35         super(maxThreadCount, threadFactory);
36     }
37
38     @Inject
39     public GlobalNetconfSshScheduledExecutor(final GlobalNetconfThreadFactory threadFactory) {
40         this(threadFactory, DEFAULT_MAX_THREAD_COUNT);
41     }
42
43     @Activate
44     public GlobalNetconfSshScheduledExecutor(final Map<String, ?> properties) {
45         this(GlobalNetconfConfiguration.extractProp(properties, PROP_THREAD_FACTORY, GlobalNetconfThreadFactory.class),
46             GlobalNetconfConfiguration.extractProp(properties, PROP_MAX_THREAD_COUNT, Integer.class));
47     }
48
49     @Override
50     @PreDestroy
51     @Deactivate
52     public void close() {
53         super.close();
54     }
55
56     static Map<String, ?> props(final GlobalNetconfThreadFactory threadFactory, final Configuration configuration) {
57         return Map.of(
58             "type", OSGI_TYPE,
59             PROP_MAX_THREAD_COUNT, configuration.max$_$thread$_$count$_$scheduled$_$thread$_$pool(),
60             PROP_THREAD_FACTORY, requireNonNull(threadFactory));
61     }
62 }