/* * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.dom.adapter.osgi; import java.util.function.Function; import org.opendaylight.mdsal.binding.api.BindingService; import org.opendaylight.mdsal.dom.api.DOMService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A ServiceTracker which adapts a DOMService to a BindingService. * * @param DOMService type * @param BindingService type * @author Robert Varga */ final class AdaptingTracker extends AbstractAdaptingTracker> { private static final Logger LOG = LoggerFactory.getLogger(AdaptingTracker.class); AdaptingTracker(final BundleContext ctx, final Class domClass, final Class bindingClass, final Function bindingFactory) { super(ctx, domClass, bindingClass, bindingFactory); } @Override ServiceRegistration addingService(final ServiceReference reference, final D dom, final B binding) { final Dict props = Dict.fromReference(reference); final ServiceRegistration reg = context.registerService(bindingClass, binding, props); LOG.debug("Registered {} adapter {} of {} with {} as {}", bindingClass.getName(), binding, dom, props, reg); return reg; } @Override void removedService(final ServiceRegistration service) { service.unregister(); } @Override void updatedService(final ServiceReference reference, final ServiceRegistration service) { final Dict newProps = Dict.fromReference(reference); LOG.debug("Updating service {} with properties {}", service, newProps); service.setProperties(newProps); } }