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