2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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.mdsal.binding.dom.adapter.osgi;
10 import java.util.function.Function;
11 import org.opendaylight.mdsal.binding.api.BindingService;
12 import org.opendaylight.mdsal.dom.api.DOMService;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.framework.ServiceRegistration;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * A ServiceTracker which adapts a DOMService to a BindingService.
22 * @param <D> DOMService type
23 * @param <B> BindingService type
24 * @author Robert Varga
26 final class AdaptingTracker<D extends DOMService, B extends BindingService>
27 extends AbstractAdaptingTracker<D, B, ServiceRegistration<B>> {
28 private static final Logger LOG = LoggerFactory.getLogger(AdaptingTracker.class);
30 AdaptingTracker(final BundleContext ctx, final Class<D> domClass, final Class<B> bindingClass,
31 final Function<D, B> bindingFactory) {
32 super(ctx, domClass, bindingClass, bindingFactory);
36 ServiceRegistration<B> addingService(final ServiceReference<D> reference, final D dom, final B binding) {
37 final Dict props = Dict.fromReference(reference);
38 final ServiceRegistration<B> reg = context.registerService(bindingClass, binding, props);
39 LOG.debug("Registered {} adapter {} of {} with {} as {}", bindingClass.getName(), binding, dom, props, reg);
44 void removedService(final ServiceRegistration<B> service) {
49 void updatedService(final ServiceReference<D> reference, final ServiceRegistration<B> service) {
50 final Dict newProps = Dict.fromReference(reference);
51 LOG.debug("Updating service {} with properties {}", service, newProps);
52 service.setProperties(newProps);