14c47352a8409d633dca64a01db06759ad79f8f6
[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 org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
11 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
12 import org.osgi.framework.BundleActivator;
13 import org.osgi.framework.BundleContext;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class NetconfMonitoringActivator implements BundleActivator {
18
19     private static final Logger logger = LoggerFactory.getLogger(NetconfMonitoringActivator.class);
20
21     private NetconfMonitoringServiceTracker monitor;
22
23     @Override
24     public void start(final BundleContext context)  {
25         monitor = new NetconfMonitoringServiceTracker(context);
26         monitor.open();
27
28     }
29
30     @Override
31     public void stop(final BundleContext context) {
32         if(monitor!=null) {
33             try {
34                 monitor.close();
35             } catch (Exception e) {
36                 logger.warn("Ignoring exception while closing {}", monitor, e);
37             }
38         }
39     }
40
41     public static class NetconfMonitoringOperationServiceFactory implements NetconfOperationServiceFactory {
42         private final NetconfMonitoringOperationService operationService;
43
44         public NetconfMonitoringOperationServiceFactory(NetconfMonitoringOperationService operationService) {
45             this.operationService = operationService;
46         }
47
48         @Override
49         public NetconfOperationService createService(String netconfSessionIdForReporting) {
50             return operationService;
51         }
52     }
53 }