Refactor DOMYangTextSourceProvider
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 6 Jan 2024 03:48:25 +0000 (04:48 +0100)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2024 00:41:48 +0000 (10:41 +1000)
This should really be a proper extension with its own API. While we are
at it.

mdsal-binding-runtime-api is made synchronous, as there is just no need
to use futures.

Change-Id: I3711662242df8d912c2536a3d73d4f86beea2c33
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-runtime-api/pom.xml
binding/mdsal-binding-runtime-api/src/main/java/module-info.java
binding/mdsal-binding-runtime-api/src/main/java/org/opendaylight/mdsal/binding/runtime/api/ModuleInfoSnapshot.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/DefaultModuleInfoSnapshot.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/ForwardingModuleInfoSnapshot.java

index 06a9bd48547fa96f0214ec918811f13fd5cf7bf8..87261eaeaa17addc5b4f7cfab5c495b99dc2c2ea 100644 (file)
@@ -46,7 +46,7 @@
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-repo-spi</artifactId>
+            <artifactId>yang-repo-api</artifactId>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
index e39a79178395cbc8a8d465055d56692f3c45cb18..dabf23dd6767d421464ce704eff46e04dfa566bd 100644 (file)
@@ -11,8 +11,8 @@ module org.opendaylight.mdsal.binding.runtime.api {
     requires transitive org.opendaylight.yangtools.concepts;
     requires transitive org.opendaylight.yangtools.yang.common;
     requires transitive org.opendaylight.yangtools.yang.model.api;
+    requires transitive org.opendaylight.yangtools.yang.repo.api;
     requires transitive org.opendaylight.yangtools.yang.binding;
-    requires transitive org.opendaylight.yangtools.yang.repo.spi;
     requires transitive org.opendaylight.yangtools.rfc8040.model.api;
     requires transitive org.opendaylight.mdsal.binding.model.api;
     requires org.slf4j;
index fa70bfb1f69accd2492e45ef5432433921ba407b..9b2b722d45b4ee2ae5ea3e8d35a4e7be0d615444 100644 (file)
@@ -8,24 +8,31 @@
 package org.opendaylight.mdsal.binding.runtime.api;
 
 import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
-import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 
 /**
  * A snapshot of a set of {@link YangModuleInfo}s, assembled to form an {@link EffectiveModelContext}.
  */
 @Beta
-public interface ModuleInfoSnapshot extends Immutable, SchemaSourceProvider<YangTextSource> {
+@NonNullByDefault
+public interface ModuleInfoSnapshot extends Immutable {
     /**
      * The {@link EffectiveModelContext} resulting from all models exposed from constituent module infos.
      *
      * @return the resulting model context
      */
-    @NonNull EffectiveModelContext modelContext();
+    EffectiveModelContext modelContext();
+
+    @Nullable YangTextSource yangTextSource(SourceIdentifier sourceId);
+
+    YangTextSource getYangTextSource(SourceIdentifier sourceId) throws MissingSchemaSourceException;
 
     <T> Class<T> loadClass(String fullyQualifiedName) throws ClassNotFoundException;
 }
index 94298c1bb1bae829a7640a8899e3207d7baf22f3..a439c50899211fb61fa2a76231c34434784e7761 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.mdsal.binding.runtime.spi;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableMap;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Map;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
@@ -41,11 +39,18 @@ final class DefaultModuleInfoSnapshot implements ModuleInfoSnapshot {
     }
 
     @Override
-    public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceId) {
+    public YangTextSource yangTextSource(final SourceIdentifier sourceId) {
         final var info = moduleInfos.get(sourceId);
-        return info == null
-            ? Futures.immediateFailedFuture(new MissingSchemaSourceException(sourceId, "No source registered"))
-                : Futures.immediateFuture(new DelegatedYangTextSource(sourceId, info.getYangTextCharSource()));
+        return info == null ? null : new DelegatedYangTextSource(sourceId, info.getYangTextCharSource());
+    }
+
+    @Override
+    public YangTextSource getYangTextSource(final SourceIdentifier sourceId) throws MissingSchemaSourceException {
+        final var source = yangTextSource(sourceId);
+        if (source == null) {
+            throw new MissingSchemaSourceException(sourceId, "No source registered");
+        }
+        return source;
     }
 
     @Override
index 1564797e7e51908819449b7fad3260030120a627..705573915fcf238dae7d8a72f2b76de7322f3966 100644 (file)
@@ -9,14 +9,16 @@ package org.opendaylight.mdsal.binding.runtime.spi;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ForwardingObject;
-import com.google.common.util.concurrent.ListenableFuture;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.runtime.api.ModuleInfoSnapshot;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.source.YangTextSource;
+import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 
 @Beta
+@NonNullByDefault
 public abstract class ForwardingModuleInfoSnapshot extends ForwardingObject implements ModuleInfoSnapshot {
     @Override
     protected abstract ModuleInfoSnapshot delegate();
@@ -27,12 +29,17 @@ public abstract class ForwardingModuleInfoSnapshot extends ForwardingObject impl
     }
 
     @Override
-    public @NonNull EffectiveModelContext modelContext() {
+    public EffectiveModelContext modelContext() {
         return delegate().modelContext();
     }
 
     @Override
-    public ListenableFuture<? extends YangTextSource> getSource(final SourceIdentifier sourceIdentifier) {
-        return delegate().getSource(sourceIdentifier);
+    public @Nullable YangTextSource yangTextSource(final SourceIdentifier sourceId) {
+        return delegate().yangTextSource(sourceId);
+    }
+
+    @Override
+    public YangTextSource getYangTextSource(final SourceIdentifier sourceId) throws MissingSchemaSourceException {
+        return delegate().getYangTextSource(sourceId);
     }
 }