813a59d2a0a09ccb78be4e967c9531cf955d32d1
[netconf.git] / netconf / mdsal-netconf-impl / src / main / java / org / opendaylight / netconf / impl / mdsal / 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.impl.mdsal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Map;
13 import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
14 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
15 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
16 import org.opendaylight.netconf.server.osgi.NetconfMonitoringServiceImpl;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20
21 @Component(factory = DefaultNetconfMonitoringService.FACTORY_NAME, service = NetconfMonitoringService.class)
22 public final class DefaultNetconfMonitoringService extends NetconfMonitoringServiceImpl {
23     static final String FACTORY_NAME = "org.opendaylight.netconf.impl.mdsal.DefaultNetconfMonitoringService";
24
25     private static final String OP_PROVIDER_PROP = ".opProvider";
26     private static final String THREAD_POOL_PROP = ".threadPool";
27     private static final String UPDATE_INTERVAL_PROP = ".updateInterval";
28
29     @Activate
30     public DefaultNetconfMonitoringService(final Map<String, ?> properties) {
31         super(OSGiNetconfServer.extractProp(properties, OP_PROVIDER_PROP, NetconfOperationServiceFactory.class),
32             OSGiNetconfServer.extractProp(properties, THREAD_POOL_PROP, ScheduledThreadPool.class),
33             OSGiNetconfServer.extractProp(properties, UPDATE_INTERVAL_PROP, Long.class));
34     }
35
36     @Override
37     @Deactivate
38     public void close() {
39         super.close();
40     }
41
42     static Map<String, ?> props(final NetconfOperationServiceFactory opProvider, final ScheduledThreadPool threadPool,
43             final long updateInterval) {
44         return Map.of(
45             "type", "netconf-server-monitoring",
46             OP_PROVIDER_PROP, requireNonNull(opProvider),
47             THREAD_POOL_PROP, requireNonNull(threadPool),
48             UPDATE_INTERVAL_PROP, updateInterval);
49     }
50 }