2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.impl.osgi;
10 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
11 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener;
12 import org.opendaylight.netconf.api.util.NetconfConstants;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.util.tracker.ServiceTracker;
17 class NetconfOperationServiceFactoryTracker extends
18 ServiceTracker<NetconfOperationServiceFactory, NetconfOperationServiceFactory> {
19 private final NetconfOperationServiceFactoryListener factoriesListener;
21 NetconfOperationServiceFactoryTracker(BundleContext context,
22 final NetconfOperationServiceFactoryListener factoriesListener) {
23 super(context, NetconfOperationServiceFactory.class, null);
24 this.factoriesListener = factoriesListener;
28 public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
29 Object property = reference.getProperty(NetconfConstants.SERVICE_NAME);
30 if (property != null && isMarkedForConfig(property)) {
31 NetconfOperationServiceFactory netconfOperationServiceFactory = super.addingService(reference);
32 factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory);
33 return netconfOperationServiceFactory;
40 public void removedService(ServiceReference<NetconfOperationServiceFactory> reference,
41 NetconfOperationServiceFactory netconfOperationServiceFactory) {
42 if (netconfOperationServiceFactory != null) {
43 factoriesListener.onRemoveNetconfOperationServiceFactory(netconfOperationServiceFactory);
47 private boolean isMarkedForConfig(Object property) {
48 return NetconfConstants.CONFIG_SERVICE_MARKERS.contains(property);