Eliminate GlobalNetconfSshScheduledExecutor
[netconf.git] / apps / netconf-nb / src / main / java / org / opendaylight / netconf / northbound / DefaultNetconfMonitoringService.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.northbound;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ThreadFactoryBuilder;
13 import java.util.Map;
14 import java.util.concurrent.ThreadFactory;
15 import java.util.concurrent.TimeUnit;
16 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
17 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
18 import org.opendaylight.netconf.server.osgi.NetconfMonitoringServiceImpl;
19 import org.osgi.service.component.annotations.Activate;
20 import org.osgi.service.component.annotations.Component;
21 import org.osgi.service.component.annotations.Deactivate;
22
23 @Component(factory = DefaultNetconfMonitoringService.FACTORY_NAME, service = NetconfMonitoringService.class)
24 public final class DefaultNetconfMonitoringService extends NetconfMonitoringServiceImpl {
25     static final String FACTORY_NAME = "org.opendaylight.netconf.impl.mdsal.DefaultNetconfMonitoringService";
26
27     private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder()
28         .setNameFormat("netconf-server-monitoring-%d")
29         .setDaemon(true)
30         .build();
31     private static final String OP_PROVIDER_PROP = ".opProvider";
32     private static final String UPDATE_INTERVAL_PROP = ".updateInterval";
33
34     private DefaultNetconfMonitoringService(final NetconfOperationServiceFactory opProvider, final long periodSeconds) {
35         super(opProvider, THREAD_FACTORY, periodSeconds, TimeUnit.SECONDS);
36     }
37
38     @Activate
39     public DefaultNetconfMonitoringService(final Map<String, ?> properties) {
40         this(OSGiNetconfServer.extractProp(properties, OP_PROVIDER_PROP, NetconfOperationServiceFactory.class),
41             OSGiNetconfServer.extractProp(properties, UPDATE_INTERVAL_PROP, Long.class));
42     }
43
44     @Override
45     @Deactivate
46     public void close() {
47         super.close();
48     }
49
50     static Map<String, ?> props(final NetconfOperationServiceFactory opProvider, final long updateInterval) {
51         return Map.of(
52             "type", "netconf-server-monitoring",
53             OP_PROVIDER_PROP, requireNonNull(opProvider),
54             UPDATE_INTERVAL_PROP, updateInterval);
55     }
56 }