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.dom.schema.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.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
18 import org.opendaylight.mdsal.dom.schema.osgi.ModelGenerationAware;
19 import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
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 @Component(factory = OSGiModuleInfoSnapshotImpl.FACTORY_NAME, service = OSGiModuleInfoSnapshot.class)
30 public final class OSGiModuleInfoSnapshotImpl implements OSGiModuleInfoSnapshot {
31 // OSGi DS Component Factory name
32 static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.OSGiEffectiveModelImpl";
34 // Keys to for activation properties
36 static final String GENERATION = "org.opendaylight.mdsal.dom.schema.osgi.impl.Generation";
38 static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.impl.ModuleInfoSnapshot";
40 private static final Logger LOG = LoggerFactory.getLogger(OSGiModuleInfoSnapshotImpl.class);
42 private ModuleInfoSnapshot delegate;
43 private UnsignedLong generation;
46 public UnsignedLong getGeneration() {
47 return verifyNotNull(generation);
51 public ModuleInfoSnapshot getService() {
52 return verifyNotNull(delegate);
56 void activate(final Map<String, ?> properties) {
57 generation = (UnsignedLong) verifyNotNull(properties.get(GENERATION));
58 delegate = (ModuleInfoSnapshot) verifyNotNull(properties.get(DELEGATE));
59 LOG.info("EffectiveModelContext generation {} activated", generation);
65 LOG.info("EffectiveModelContext generation {} deactivated", generation);
68 static Dictionary<String, ?> props(final long generation, final ModuleInfoSnapshot delegate) {
69 return FrameworkUtil.asDictionary(Map.of(
70 Constants.SERVICE_RANKING, ModelGenerationAware.computeServiceRanking(generation),
71 GENERATION, UnsignedLong.fromLongBits(generation),