Move BindingReflections.cacheModuleInfos()
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 12:16:30 +0000 (14:16 +0200)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2024 00:41:46 +0000 (10:41 +1000)
This caching is only used in AbstractSchemaAwareTest, move them there.

JIRA: MDSAL-781
Change-Id: Id0f9d16f5ec046e7b545486aabbfca7e706b9f2e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/BindingRuntimeHelpers.java
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java

index 38c4c35d593820840e682d46c7abfc9818f12704..199b4ab247bca3d7b8e6a0403c40f507dd378f30 100644 (file)
@@ -119,8 +119,12 @@ public final class BindingRuntimeHelpers {
     }
 
     public static @NonNull ImmutableSet<YangModuleInfo> loadModuleInfos() {
+        return loadModuleInfos(Thread.currentThread().getContextClassLoader());
+    }
+
+    public static @NonNull ImmutableSet<YangModuleInfo> loadModuleInfos(final ClassLoader classLoader) {
         final var moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
-        for (var bindingProvider : ServiceLoader.load(YangModelBindingProvider.class)) {
+        for (var bindingProvider : ServiceLoader.load(YangModelBindingProvider.class, classLoader)) {
             var moduleInfo = bindingProvider.getModuleInfo();
             checkState(moduleInfo != null, "Module Info for %s is not available.", bindingProvider.getClass());
             collectYangModuleInfo(bindingProvider.getModuleInfo(), moduleInfoSet);
index 1fa8ffa023e3f4de9d802283763fce30097eec03..d941482c5f42f2693b8a3b1dd7498090e00ce241 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.mdsal.binding.spec.reflect;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 
-import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -50,14 +49,6 @@ public final class BindingReflections {
             .weakKeys()
             .expireAfterAccess(60, TimeUnit.SECONDS)
             .build(new ClassToQNameLoader());
-    private static final LoadingCache<ClassLoader, ImmutableSet<YangModuleInfo>> MODULE_INFO_CACHE =
-            CacheBuilder.newBuilder().weakKeys().weakValues().build(
-                new CacheLoader<ClassLoader, ImmutableSet<YangModuleInfo>>() {
-                    @Override
-                    public ImmutableSet<YangModuleInfo> load(final ClassLoader key) {
-                        return loadModuleInfos(key);
-                    }
-                });
 
     private BindingReflections() {
         // Hidden on purpose
@@ -201,9 +192,6 @@ public final class BindingReflections {
      * When {@link YangModuleInfo} is available, all dependencies are recursively collected into returning set by
      * collecting results of {@link YangModuleInfo#getImportedModules()}.
      *
-     * <p>
-     * Consider using {@link #cacheModuleInfos(ClassLoader)} if the classloader is known to be immutable.
-     *
      * @param loader Classloader for which {@link YangModuleInfo} should be retrieved.
      * @return Set of {@link YangModuleInfo} available for supplied classloader.
      */
@@ -219,27 +207,6 @@ public final class BindingReflections {
         return moduleInfoSet.build();
     }
 
-    /**
-     * Loads {@link YangModuleInfo} instances available on supplied {@link ClassLoader}, assuming the set of available
-     * information does not change. Subsequent accesses may return cached values.
-     *
-     * <p>
-     * {@link YangModuleInfo} are discovered using {@link ServiceLoader} for {@link YangModelBindingProvider}.
-     * {@link YangModelBindingProvider} are simple classes which holds only pointers to actual instance
-     * {@link YangModuleInfo}.
-     *
-     * <p>
-     * When {@link YangModuleInfo} is available, all dependencies are recursively collected into returning set by
-     * collecting results of {@link YangModuleInfo#getImportedModules()}.
-     *
-     * @param loader Class loader for which {@link YangModuleInfo} should be retrieved.
-     * @return Set of {@link YangModuleInfo} available for supplied classloader.
-     */
-    @Beta
-    public static @NonNull ImmutableSet<YangModuleInfo> cacheModuleInfos(final ClassLoader loader) {
-        return MODULE_INFO_CACHE.getUnchecked(loader);
-    }
-
     private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
             final Builder<YangModuleInfo> moduleInfoSet) {
         moduleInfoSet.add(moduleInfo);