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;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.annotations.Beta;
14 import com.google.common.annotations.VisibleForTesting;
15 import com.google.common.primitives.UnsignedLong;
16 import java.util.Dictionary;
17 import java.util.Hashtable;
19 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
20 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
21 import org.opendaylight.mdsal.dom.schema.osgi.ModelGenerationAware;
22 import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
23 import org.osgi.framework.Constants;
24 import org.osgi.service.component.annotations.Activate;
25 import org.osgi.service.component.annotations.Component;
26 import org.osgi.service.component.annotations.Deactivate;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 @Component(factory = OSGiModuleInfoSnapshotImpl.FACTORY_NAME, service = OSGiModuleInfoSnapshot.class)
32 public final class OSGiModuleInfoSnapshotImpl implements OSGiModuleInfoSnapshot {
33 // OSGi DS Component Factory name
34 static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.OSGiEffectiveModelImpl";
36 // Keys to for activation properties
38 static final String GENERATION = "org.opendaylight.mdsal.dom.schema.osgi.impl.Generation";
40 static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.impl.ModuleInfoSnapshot";
42 private static final Logger LOG = LoggerFactory.getLogger(OSGiModuleInfoSnapshotImpl.class);
44 private ModuleInfoSnapshot delegate;
45 private UnsignedLong generation;
48 public UnsignedLong getGeneration() {
49 return verifyNotNull(generation);
53 public ModuleInfoSnapshot getService() {
54 return verifyNotNull(delegate);
58 void activate(final Map<String, ?> properties) {
59 generation = (UnsignedLong) verifyNotNull(properties.get(GENERATION));
60 delegate = (ModuleInfoSnapshot) verifyNotNull(properties.get(DELEGATE));
61 LOG.info("EffectiveModelContext generation {} activated", generation);
67 LOG.info("EffectiveModelContext generation {} deactivated", generation);
71 static Dictionary<String, ?> props(final long generation, final ModuleInfoSnapshot delegate) {
72 final Dictionary<String, Object> ret = new Hashtable<>(4);
73 ret.put(Constants.SERVICE_RANKING, ModelGenerationAware.computeServiceRanking(generation));
74 ret.put(GENERATION, UnsignedLong.fromLongBits(generation));
75 ret.put(DELEGATE, requireNonNull(delegate));