BUG-2635 Netconf monitoring for md-sal netconf northbound
[controller.git] / opendaylight / netconf / netconf-monitoring / src / main / java / org / opendaylight / controller / netconf / monitoring / osgi / NetconfMonitoringActivator.java
1 /*
2 * Copyright (c) 2013 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.netconf.monitoring.osgi;
9
10 import java.util.Collections;
11 import java.util.Set;
12 import org.opendaylight.controller.netconf.api.Capability;
13 import org.opendaylight.controller.netconf.api.monitoring.CapabilityListener;
14 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
15 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
16 import org.osgi.framework.BundleActivator;
17 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class NetconfMonitoringActivator implements BundleActivator {
22
23     private static final Logger LOG = LoggerFactory.getLogger(NetconfMonitoringActivator.class);
24
25     private NetconfMonitoringServiceTracker monitor;
26
27     @Override
28     public void start(final BundleContext context)  {
29         monitor = new NetconfMonitoringServiceTracker(context);
30         monitor.open();
31     }
32
33     @Override
34     public void stop(final BundleContext context) {
35         if(monitor!=null) {
36             try {
37                 monitor.close();
38             } catch (final Exception e) {
39                 LOG.warn("Ignoring exception while closing {}", monitor, e);
40             }
41         }
42     }
43
44     public static class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable {
45
46         private final NetconfMonitoringOperationService operationService;
47
48         private static final AutoCloseable AUTO_CLOSEABLE = new AutoCloseable() {
49             @Override
50             public void close() throws Exception {
51                 // NOOP
52             }
53         };
54
55         public NetconfMonitoringOperationServiceFactory(final NetconfMonitoringOperationService operationService) {
56             this.operationService = operationService;
57         }
58
59         @Override
60         public NetconfOperationService createService(final String netconfSessionIdForReporting) {
61             return operationService;
62         }
63
64         @Override
65         public Set<Capability> getCapabilities() {
66             return Collections.emptySet();
67         }
68
69         @Override
70         public AutoCloseable registerCapabilityListener(final CapabilityListener listener) {
71             return AUTO_CLOSEABLE;
72         }
73
74         @Override
75         public void close() {}
76     }
77 }