Search in sources :

Example 1 with ModuleInfoSnapshot

use of org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot in project mdsal by opendaylight.

the class OSGiDOMSchemaService method bindSnapshot.

@Reference(policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
void bindSnapshot(final OSGiModuleInfoSnapshot newContext) {
    LOG.info("Updating context to generation {}", newContext.getGeneration());
    final ModuleInfoSnapshot snapshot = newContext.getService();
    final EffectiveModelContext ctx = snapshot.getEffectiveModelContext();
    final ModuleInfoSnapshot previous = currentSnapshot.getAndSet(snapshot);
    LOG.debug("Snapshot updated from {} to {}", previous, snapshot);
    listeners.forEach(listener -> notifyListener(ctx, listener));
}
Also used : OSGiModuleInfoSnapshot(org.opendaylight.mdsal.dom.schema.osgi.OSGiModuleInfoSnapshot) ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) Reference(org.osgi.service.component.annotations.Reference)

Example 2 with ModuleInfoSnapshot

use of org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot in project mdsal by opendaylight.

the class ModuleInfoSnapshotResolver method updateSnapshot.

@Holding("this")
@NonNull
private ModuleInfoSnapshot updateSnapshot(final EffectiveModelContext effectiveModel) {
    // Alright, now let's find out which sources got captured
    final Set<SourceIdentifier> sources = new HashSet<>();
    for (Entry<QNameModule, ModuleEffectiveStatement> entry : effectiveModel.getModuleStatements().entrySet()) {
        final Optional<Revision> revision = entry.getKey().getRevision();
        final ModuleEffectiveStatement module = entry.getValue();
        sources.add(RevisionSourceIdentifier.create(module.argument().getLocalName(), revision));
        module.streamEffectiveSubstatements(SubmoduleEffectiveStatement.class).map(submodule -> RevisionSourceIdentifier.create(submodule.argument().getLocalName(), revision)).forEach(sources::add);
    }
    final Map<SourceIdentifier, YangModuleInfo> moduleInfos = new HashMap<>();
    final Map<String, ClassLoader> classLoaders = new HashMap<>();
    for (SourceIdentifier source : sources) {
        final List<RegisteredModuleInfo> regs = sourceToInfoReg.get(source);
        checkState(!regs.isEmpty(), "No registration for %s", source);
        final RegisteredModuleInfo reg = regs.get(0);
        final YangModuleInfo info = reg.info;
        moduleInfos.put(source, info);
        final Class<?> infoClass = info.getClass();
        classLoaders.put(BindingReflections.getModelRootPackageName(infoClass.getPackage()), infoClass.getClassLoader());
    }
    final ModuleInfoSnapshot next = new DefaultModuleInfoSnapshot(effectiveModel, moduleInfos, classLoaders);
    currentSnapshot = next;
    return next;
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) ListMultimap(com.google.common.collect.ListMultimap) YangSyntaxErrorException(org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException) MultimapBuilder(com.google.common.collect.MultimapBuilder) Mutable(org.opendaylight.yangtools.concepts.Mutable) BindingReflections(org.opendaylight.mdsal.binding.spec.reflect.BindingReflections) LoggerFactory(org.slf4j.LoggerFactory) YangParserFactory(org.opendaylight.yangtools.yang.parser.api.YangParserFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) HashSet(java.util.HashSet) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) ImmutableList(com.google.common.collect.ImmutableList) Nullable(org.eclipse.jdt.annotation.Nullable) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) YangTextSchemaContextResolver(org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver) LinkedHashSet(java.util.LinkedHashSet) ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) Logger(org.slf4j.Logger) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) MoreObjects(com.google.common.base.MoreObjects) Set(java.util.Set) IOException(java.io.IOException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) SubmoduleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement) QName(org.opendaylight.yangtools.yang.common.QName) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Beta(com.google.common.annotations.Beta) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) List(java.util.List) Holding(org.checkerframework.checker.lock.qual.Holding) AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) Revision(org.opendaylight.yangtools.yang.common.Revision) GuardedBy(org.checkerframework.checker.lock.qual.GuardedBy) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) Entry(java.util.Map.Entry) Optional(java.util.Optional) SchemaSourceException(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException) Registration(org.opendaylight.yangtools.concepts.Registration) Builder(com.google.common.collect.ImmutableList.Builder) NonNull(org.eclipse.jdt.annotation.NonNull) ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) HashMap(java.util.HashMap) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) YangModuleInfo(org.opendaylight.yangtools.yang.binding.YangModuleInfo) Revision(org.opendaylight.yangtools.yang.common.Revision) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 3 with ModuleInfoSnapshot

use of org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot in project lighty-netconf-simulator by PANTHEONtech.

the class NetconfDeviceServicesImpl method createAdapterContext.

private AdapterContext createAdapterContext(Collection<YangModuleInfo> moduleInfos) {
    final YangParserFactory yangParserFactory = new DefaultYangParserFactory();
    ModuleInfoSnapshotResolver snapshotResolver = new ModuleInfoSnapshotResolver("netconf-simulator", yangParserFactory);
    snapshotResolver.registerModuleInfos(moduleInfos);
    ModuleInfoSnapshot moduleInfoSnapshot = snapshotResolver.takeSnapshot();
    final BindingRuntimeGenerator bindingRuntimeGenerator = new DefaultBindingRuntimeGenerator();
    final BindingRuntimeTypes bindingRuntimeTypes = bindingRuntimeGenerator.generateTypeMapping(moduleInfoSnapshot.getEffectiveModelContext());
    final DefaultBindingRuntimeContext bindingRuntimeContext = new DefaultBindingRuntimeContext(bindingRuntimeTypes, moduleInfoSnapshot);
    final BindingCodecContext bindingCodecContext = new BindingCodecContext(bindingRuntimeContext);
    return new ConstantAdapterContext(bindingCodecContext);
}
Also used : ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) ConstantAdapterContext(org.opendaylight.mdsal.binding.dom.adapter.ConstantAdapterContext) DefaultBindingRuntimeGenerator(org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator) BindingCodecContext(org.opendaylight.mdsal.binding.dom.codec.impl.BindingCodecContext) BindingRuntimeTypes(org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeTypes) DefaultYangParserFactory(org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory) ModuleInfoSnapshotResolver(org.opendaylight.mdsal.binding.runtime.spi.ModuleInfoSnapshotResolver) DefaultBindingRuntimeContext(org.opendaylight.mdsal.binding.runtime.api.DefaultBindingRuntimeContext) YangParserFactory(org.opendaylight.yangtools.yang.parser.api.YangParserFactory) DefaultYangParserFactory(org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory) DefaultBindingRuntimeGenerator(org.opendaylight.mdsal.binding.generator.impl.DefaultBindingRuntimeGenerator) BindingRuntimeGenerator(org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeGenerator)

Example 4 with ModuleInfoSnapshot

use of org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot in project mdsal by opendaylight.

the class ModuleInfoSnapshotResolver method takeSnapshot.

@NonNull
public synchronized ModuleInfoSnapshot takeSnapshot() {
    final EffectiveModelContext effectiveModel = ctxResolver.getEffectiveModelContext().orElseThrow();
    final ModuleInfoSnapshot local = currentSnapshot;
    if (local != null && local.getEffectiveModelContext().equals(effectiveModel)) {
        return local;
    }
    return updateSnapshot(effectiveModel);
}
Also used : ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 5 with ModuleInfoSnapshot

use of org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot in project mdsal by opendaylight.

the class RegularYangModuleInfoRegistry method updateService.

@Holding("this")
private void updateService() {
    final ModuleInfoSnapshot newSnapshot;
    try {
        newSnapshot = moduleInfoRegistry.takeSnapshot();
    } catch (NoSuchElementException e) {
        LOG.debug("No snapshot available", e);
        return;
    }
    if (newSnapshot.equals(currentSnapshot)) {
        LOG.debug("No update to snapshot");
        return;
    }
    final ComponentInstance<OSGiModuleInfoSnapshotImpl> newInstance = contextFactory.newInstance(OSGiModuleInfoSnapshotImpl.props(nextGeneration(), newSnapshot));
    if (currentInstance != null) {
        currentInstance.dispose();
    }
    currentInstance = newInstance;
    currentSnapshot = newSnapshot;
}
Also used : ModuleInfoSnapshot(org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot) NoSuchElementException(java.util.NoSuchElementException) Holding(org.checkerframework.checker.lock.qual.Holding)

Aggregations

ModuleInfoSnapshot (org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot)5 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Holding (org.checkerframework.checker.lock.qual.Holding)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 YangParserFactory (org.opendaylight.yangtools.yang.parser.api.YangParserFactory)2 Beta (com.google.common.annotations.Beta)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Builder (com.google.common.collect.ImmutableList.Builder)1 ListMultimap (com.google.common.collect.ListMultimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1