Make OSGiModuleInfoSnapshot generation unsigned
[mdsal.git] / binding / mdsal-binding-runtime-osgi / src / main / java / org / opendaylight / mdsal / binding / runtime / osgi / impl / BindingRuntimeContextImpl.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.runtime.osgi.impl;
9
10 import com.google.common.primitives.UnsignedLong;
11 import org.opendaylight.binding.runtime.api.AbstractBindingRuntimeContext;
12 import org.opendaylight.binding.runtime.api.BindingRuntimeContext;
13 import org.opendaylight.binding.runtime.api.BindingRuntimeGenerator;
14 import org.opendaylight.binding.runtime.api.BindingRuntimeTypes;
15 import org.opendaylight.binding.runtime.api.ClassLoadingStrategy;
16 import org.opendaylight.binding.runtime.api.DefaultBindingRuntimeContext;
17 import org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot;
18 import org.osgi.service.component.annotations.Activate;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
21 import org.osgi.service.component.annotations.Reference;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * A Factory Component which implements {@link BindingRuntimeContext}.
27  */
28 @Component(service = BindingRuntimeContext.class, immediate = true)
29 public final class BindingRuntimeContextImpl extends AbstractBindingRuntimeContext {
30     private static final Logger LOG = LoggerFactory.getLogger(BindingRuntimeContextImpl.class);
31
32     @Reference
33     OSGiModuleInfoSnapshot effectiveModel = null;
34     @Reference
35     BindingRuntimeGenerator generator = null;
36
37     private BindingRuntimeContext delegate;
38     private UnsignedLong generation;
39
40     @Override
41     public ClassLoadingStrategy getStrategy() {
42         return delegate.getStrategy();
43     }
44
45     @Override
46     public BindingRuntimeTypes getTypes() {
47         return delegate.getTypes();
48     }
49
50     @Activate
51     void activate() {
52         generation = effectiveModel.getGeneration();
53         delegate = DefaultBindingRuntimeContext.create(
54             generator.generateTypeMapping(effectiveModel.getEffectiveModelContext()), effectiveModel);
55
56         LOG.debug("BindingRuntimeContext generation {} activated", generation);
57     }
58
59     @Deactivate
60     void deactivate() {
61         delegate = null;
62         LOG.debug("BindingRuntimeContext generation {} deactivated", generation);
63     }
64 }