import static java.util.Objects.requireNonNull;
+import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.NoSuchElementException;
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.checkerframework.checker.lock.qual.Holding;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
import org.opendaylight.mdsal.binding.runtime.spi.ModuleInfoSnapshotResolver;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.concepts.AbstractRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataRoot;
+import org.opendaylight.yangtools.yang.binding.YangFeatureProvider;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.parser.api.YangParserFactory;
import org.osgi.service.component.ComponentFactory;
final class RegularYangModuleInfoRegistry extends YangModuleInfoRegistry {
private static final Logger LOG = LoggerFactory.getLogger(RegularYangModuleInfoRegistry.class);
- private final ComponentFactory contextFactory;
- private final ModuleInfoSnapshotResolver moduleInfoRegistry;
+ private final ComponentFactory<OSGiModuleInfoSnapshotImpl> contextFactory;
+ private final ModuleInfoSnapshotResolver resolver;
@GuardedBy("this")
- private ComponentInstance currentInstance;
+ private ComponentInstance<OSGiModuleInfoSnapshotImpl> currentInstance;
@GuardedBy("this")
private ModuleInfoSnapshot currentSnapshot;
@GuardedBy("this")
private volatile boolean ignoreScanner = true;
- RegularYangModuleInfoRegistry(final ComponentFactory contextFactory, final YangParserFactory factory) {
+ RegularYangModuleInfoRegistry(final ComponentFactory<OSGiModuleInfoSnapshotImpl> contextFactory,
+ final YangParserFactory factory) {
this.contextFactory = requireNonNull(contextFactory);
- moduleInfoRegistry = new ModuleInfoSnapshotResolver("binding-dom-codec", factory);
+ resolver = new ModuleInfoSnapshotResolver("dom-schema-osgi", factory);
}
// Invocation from scanner, we may want to ignore this in order to not process partial updates
}
@Override
- List<ObjectRegistration<YangModuleInfo>> registerInfos(final List<YangModuleInfo> infos) {
- return moduleInfoRegistry.registerModuleInfos(infos);
+ Registration registerBundle(final List<YangModuleInfo> moduleInfos,
+ final List<YangFeatureProvider<?>> featureProviders) {
+ final var infoRegs = resolver.registerModuleInfos(moduleInfos);
+ final var featureRegs = featureProviders.stream()
+ .map(provider -> {
+ @SuppressWarnings("unchecked")
+ final var raw = (YangFeatureProvider<@NonNull DataRoot>) provider;
+ return resolver.registerModuleFeatures(raw.boundModule(), raw.supportedFeatures());
+ })
+ .collect(ImmutableList.toImmutableList());
+
+ return new AbstractRegistration() {
+ @Override
+ protected void removeRegistration() {
+ featureRegs.forEach(Registration::close);
+ infoRegs.forEach(Registration::close);
+ }
+ };
}
@Holding("this")
private void updateService() {
final ModuleInfoSnapshot newSnapshot;
try {
- newSnapshot = moduleInfoRegistry.takeSnapshot();
+ newSnapshot = resolver.takeSnapshot();
} catch (NoSuchElementException e) {
LOG.debug("No snapshot available", e);
return;
return;
}
-
- final ComponentInstance newInstance = contextFactory.newInstance(
+ final ComponentInstance<OSGiModuleInfoSnapshotImpl> newInstance = contextFactory.newInstance(
OSGiModuleInfoSnapshotImpl.props(nextGeneration(), newSnapshot));
if (currentInstance != null) {
currentInstance.dispose();