BUG-997: fix InMemorySchemaSourceCache interface 17/10217/1
authorRobert Varga <rovarga@cisco.com>
Sun, 24 Aug 2014 17:54:34 +0000 (19:54 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 24 Aug 2014 17:57:53 +0000 (19:57 +0200)
It turns out it was impossible to instantiate this class reasonably. Add
a static factory method to alleviate.

Change-Id: Id7ed4976db6ca6303752392c9aded444491edd08
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCache.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