a4fef8b3f552fd827c6f10fe50c7e1b0efc291c7
[netconf.git] / netconf / mdsal-netconf-monitoring / src / main / java / org / opendaylight / controller / config / yang / netconf / mdsal / monitoring / MdsalMonitoringMapperFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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.controller.config.yang.netconf.mdsal.monitoring;
9
10 import java.util.Set;
11 import org.opendaylight.netconf.api.capability.Capability;
12 import org.opendaylight.netconf.api.monitoring.CapabilityListener;
13 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
14 import org.opendaylight.netconf.mapping.api.NetconfOperation;
15 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
16 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
17 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
18 import org.opendaylight.yangtools.concepts.Registration;
19
20 public final class MdsalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable {
21     private final MonitoringToMdsalWriter monitoringToMdsalWriter;
22     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
23     private final NetconfMonitoringService netconfMonitoringService;
24
25     public MdsalMonitoringMapperFactory(
26             final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
27             final NetconfMonitoringService netconfMonitoringService,
28             final MonitoringToMdsalWriter monitoringToMdsalWriter) {
29
30         this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
31         this.netconfMonitoringService = netconfMonitoringService;
32         this.monitoringToMdsalWriter = monitoringToMdsalWriter;
33         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
34     }
35
36     @Override
37     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
38         return new NetconfOperationService() {
39             @Override
40             public Set<NetconfOperation> getNetconfOperations() {
41                 return Set.of(new GetSchema(netconfSessionIdForReporting, netconfMonitoringService));
42             }
43
44             @Override
45             public void close() {
46                 // NOOP
47             }
48         };
49     }
50
51     @Override
52     public Set<Capability> getCapabilities() {
53         // TODO No capabilities exposed to prevent clashes with schemas from mdsal-netconf-connector (it exposes all the
54         // schemas). If the schemas exposed by mdsal-netconf-connector are filtered, this class would expose monitoring
55         // related models.
56         return Set.of();
57     }
58
59     @Override
60     public Registration registerCapabilityListener(final CapabilityListener listener) {
61         return () -> { };
62     }
63
64     /**
65      * Invoked using blueprint.
66      */
67     @Override
68     public void close() {
69         monitoringToMdsalWriter.close();
70         netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
71     }
72
73 }