BUG-2633 - Added Operation Service Factory Filtering for Netconf.
[controller.git] / opendaylight / netconf / netconf-impl / src / main / java / org / opendaylight / controller / netconf / impl / osgi / NetconfOperationServiceFactoryTracker.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.impl.osgi;
9
10 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
11 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.ServiceReference;
14 import org.osgi.util.tracker.ServiceTracker;
15
16 class NetconfOperationServiceFactoryTracker extends
17         ServiceTracker<NetconfOperationServiceFactory, NetconfOperationServiceFactory> {
18     private final NetconfOperationServiceFactoryListener factoriesListener;
19
20     NetconfOperationServiceFactoryTracker(BundleContext context,
21             final NetconfOperationServiceFactoryListener factoriesListener) {
22         super(context, NetconfOperationServiceFactory.class, null);
23         this.factoriesListener = factoriesListener;
24     }
25
26     @Override
27     public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
28         Object property = reference.getProperty(NetconfConstants.SERVICE_NAME);
29         if (property != null
30                 && (property.equals(NetconfConstants.CONFIG_NETCONF_CONNECTOR)
31                 || property.equals(NetconfConstants.NETCONF_MONITORING))) {
32             NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference);
33             factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
34             return netconfOperationServiceFactory;
35         }
36
37         return null;
38     }
39
40     @Override
41     public void removedService(ServiceReference<NetconfOperationServiceFactory> reference,
42             NetconfOperationServiceFactory netconfOperationServiceFactory) {
43         if (netconfOperationServiceFactory != null)
44             factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
45     }
46
47 }