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 com.google.common.util.concurrent.ListenableFuture;
17 import java.util.Dictionary;
18 import java.util.Hashtable;
20 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
21 import org.opendaylight.binding.runtime.api.ModuleInfoSnapshot;
22 import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
25 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
26 import org.osgi.framework.Constants;
27 import org.osgi.service.component.annotations.Activate;
28 import org.osgi.service.component.annotations.Component;
29 import org.osgi.service.component.annotations.Deactivate;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 @Component(factory = OSGiEffectiveModelImpl.FACTORY_NAME,
35 service = { OSGiModuleInfoSnapshot.class, ModuleInfoSnapshot.class })
36 public final class OSGiEffectiveModelImpl implements OSGiModuleInfoSnapshot {
37 // OSGi DS Component Factory name
38 static final String FACTORY_NAME = "org.opendaylight.mdsal.dom.schema.osgi.impl.OSGiEffectiveModelImpl";
40 // Keys to for activation properties
42 static final String GENERATION = "org.opendaylight.mdsal.dom.schema.osgi.impl.Generation";
44 static final String DELEGATE = "org.opendaylight.mdsal.dom.schema.osgi.impl.ModuleInfoSnapshot";
46 private static final Logger LOG = LoggerFactory.getLogger(OSGiEffectiveModelImpl.class);
48 private ModuleInfoSnapshot delegate;
49 private UnsignedLong generation;
52 public UnsignedLong getGeneration() {
57 public EffectiveModelContext getEffectiveModelContext() {
58 return delegate.getEffectiveModelContext();
62 public ListenableFuture<? extends YangTextSchemaSource> getSource(final SourceIdentifier sourceIdentifier) {
63 return delegate.getSource(sourceIdentifier);
67 public Class<?> loadClass(final String fullyQualifiedName) throws ClassNotFoundException {
68 return delegate.loadClass(fullyQualifiedName);
72 void activate(final Map<String, ?> properties) {
73 generation = (UnsignedLong) verifyNotNull(properties.get(GENERATION));
74 delegate = (ModuleInfoSnapshot) verifyNotNull(properties.get(DELEGATE));
75 LOG.debug("ClassLoadingEffectiveModelContext generation {} activated", generation);
81 LOG.debug("ClassLoadingEffectiveModelContext generation {} deactivated", generation);
85 static Dictionary<String, ?> props(final long generation, final ModuleInfoSnapshot delegate) {
86 final Dictionary<String, Object> ret = new Hashtable<>(4);
87 ret.put(Constants.SERVICE_RANKING, ranking(generation));
88 ret.put(GENERATION, UnsignedLong.fromLongBits(generation));
89 ret.put(DELEGATE, requireNonNull(delegate));
93 private static Integer ranking(final long generation) {
94 return generation >= 0 && generation <= Integer.MAX_VALUE ? (int) generation : Integer.MAX_VALUE;