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));
}
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;
}
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);
}
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);
}
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;
}
Aggregations