2 * Copyright (c) 2020 PANTHEON.tech, 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.runtime.osgi.impl;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.primitives.UnsignedLong;
15 import java.util.Dictionary;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
19 import org.opendaylight.mdsal.binding.runtime.osgi.OSGiBindingRuntimeContext;
20 import org.osgi.framework.Constants;
21 import org.osgi.framework.FrameworkUtil;
22 import org.osgi.service.component.annotations.Activate;
23 import org.osgi.service.component.annotations.Component;
24 import org.osgi.service.component.annotations.Deactivate;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * A Factory Component which implements {@link OSGiBindingRuntimeContext}.
32 @Component(factory = OSGiBindingRuntimeContextImpl.FACTORY_NAME, service = OSGiBindingRuntimeContext.class)
33 public final class OSGiBindingRuntimeContextImpl implements OSGiBindingRuntimeContext {
34 // OSGi DS Component Factory name
35 static final String FACTORY_NAME = "org.opendaylight.mdsal.binding.runtime.osgi.impl.OSGiBindingRuntimeContextImpl";
37 // Keys to for activation properties
39 static final String GENERATION = "org.opendaylight.mdsal.binding.runtime.osgi.impl.Generation";
41 static final String DELEGATE = "org.opendaylight.mdsal.binding.runtime.osgi.impl.BindingRuntimeContext";
43 private static final Logger LOG = LoggerFactory.getLogger(OSGiBindingRuntimeContextImpl.class);
45 private BindingRuntimeContext delegate;
46 private UnsignedLong generation;
49 public UnsignedLong getGeneration() {
50 return verifyNotNull(generation);
54 public BindingRuntimeContext getService() {
55 return verifyNotNull(delegate);
59 void activate(final Map<String, ?> properties) {
60 generation = (UnsignedLong) verifyNotNull(properties.get(GENERATION));
61 delegate = (BindingRuntimeContext) verifyNotNull(properties.get(DELEGATE));
62 LOG.info("BindingRuntimeContext generation {} activated", generation);
68 LOG.info("BindingRuntimeContext generation {} deactivated", generation);
71 static Dictionary<String, ?> props(final @NonNull UnsignedLong generation, final @NonNull Integer ranking,
72 final BindingRuntimeContext delegate) {
73 return FrameworkUtil.asDictionary(Map.of(
74 Constants.SERVICE_RANKING, ranking,
75 GENERATION, generation,