Bump upstreams to SNAPSHOTs
[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
19 public final class MdsalMonitoringMapperFactory implements NetconfOperationServiceFactory, AutoCloseable {
20     private final MonitoringToMdsalWriter monitoringToMdsalWriter;
21     private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
22     private final NetconfMonitoringService netconfMonitoringService;
23
24     public MdsalMonitoringMapperFactory(
25             final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
26             final NetconfMonitoringService netconfMonitoringService,
27             final MonitoringToMdsalWriter monitoringToMdsalWriter) {
28
29         this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
30         this.netconfMonitoringService = netconfMonitoringService;
31         this.monitoringToMdsalWriter = monitoringToMdsalWriter;
32         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
33     }
34
35     @Override
36     public NetconfOperationService createService(final String netconfSessionIdForReporting) {
37         return new NetconfOperationService() {
38             @Override
39             public Set<NetconfOperation> getNetconfOperations() {
40                 return Set.of(new GetSchema(netconfSessionIdForReporting, netconfMonitoringService));
41             }
42
43             @Override
44             public void close() {
45                 // NOOP
46             }
47         };
48     }
49
50     @Override
51     public Set<Capability> getCapabilities() {
52         // TODO No capabilities exposed to prevent clashes with schemas from mdsal-netconf-connector (it exposes all the
53         // schemas). If the schemas exposed by mdsal-netconf-connector are filtered, this class would expose monitoring
54         // related models.
55         return Set.of();
56     }
57
58     @Override
59     public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
60         return () -> { };
61     }
62
63     /**
64      * Invoked using blueprint.
65      */
66     @Override
67     public void close() {
68         monitoringToMdsalWriter.close();
69         netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
70     }
71
72 }