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