Merge "BUG-1605: Fixup yang-data-api interface"
authorTony Tkacik <ttkacik@cisco.com>
Mon, 25 Aug 2014 07:59:30 +0000 (07:59 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 25 Aug 2014 07:59:30 +0000 (07:59 +0000)
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCache.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySort.java

index 60dfb90a883a574c95a02e03afa472eb5d6e49d9..ad594e422116463671bb760fd75945ff647f0660 100644 (file)
@@ -6,6 +6,7 @@
  */
 package org.opendaylight.yangtools.yang.model.repo.util;
 
+import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
@@ -22,6 +23,7 @@ import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Cost
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 
+@Beta
 public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> extends AbstractSchemaSourceCache<T> {
     private static final class CacheEntry<T extends SchemaSourceRepresentation> {
         private final SchemaSourceRegistration<T> reg;
@@ -42,9 +44,13 @@ public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> ext
 
     private final Cache<SourceIdentifier, CacheEntry<T>> cache;
 
-    protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final int maxSize) {
+    protected InMemorySchemaSourceCache(final SchemaSourceRegistry consumer, final Class<T> representation, final CacheBuilder<Object, Object> builder) {
         super(consumer, representation, Costs.IMMEDIATE);
-        cache = CacheBuilder.newBuilder().softValues().maximumSize(maxSize).removalListener(LISTENER).build();
+        cache = builder.removalListener(LISTENER).build();
+    }
+
+    public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(final SchemaSourceRegistry consumer, final Class<R> representation) {
+        return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues());
     }
 
     @Override
index 7b543b730702718226447a1ba3efde9ee4cc9a17..051dd4f72729a94bb9d76f3e3c117d5797f4c282 100644 (file)
@@ -178,12 +178,25 @@ public final class ModuleDependencySort {
                 Object mod = allNS.get(ns);
                 String name = null;
                 Date revision = null;
+
+                if(mod instanceof ModuleOrModuleBuilder) {
+                    ModuleOrModuleBuilder modOrmodBuilder = ((ModuleOrModuleBuilder) mod);
+                    if(modOrmodBuilder.isModule()) {
+                        mod = ((ModuleOrModuleBuilder) mod).getModule();
+                    } else if (modOrmodBuilder.isModuleBuilder()) {
+                        mod = ((ModuleOrModuleBuilder) mod).getModuleBuilder();
+                    } else {
+                        LOGGER.warn("ModuleOrModuleBuilder is neither Module or ModuleBuilder");
+                    }
+                }
                 if (mod instanceof Module) {
                     name = ((Module) mod).getName();
                     revision = ((Module) mod).getRevision();
                 } else if (mod instanceof ModuleBuilder) {
                     name = ((ModuleBuilder) mod).getName();
                     revision = ((ModuleBuilder) mod).getRevision();
+                } else {
+                    LOGGER.warn("Module has no name: {}", mod);
                 }
                 if (!(fromName.equals(name))) {
                     LOGGER.warn(