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