BUG-994: improve object cache
[yangtools.git] / common / object-cache-guava / src / main / java / org / opendaylight / yangtools / objcache / guava / GuavaObjectCacheFactory.java
index 067b626e07a39712d0ed003427b185e3c4f87b6d..895037625ddbf04e778f5cf4829da7a1b63de073 100644 (file)
@@ -12,31 +12,27 @@ import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
 
 import com.google.common.base.FinalizableReferenceQueue;
 
-public final class GuavaObjectCacheFactory implements IObjectCacheFactory {
-       private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory();
-       private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue();
-       private final ObjectCache cache;
+public final class GuavaObjectCacheFactory implements AutoCloseable, IObjectCacheFactory {
+    private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory();
+    private final FinalizableReferenceQueue  queue = new FinalizableReferenceQueue();
+    private final ObjectCache cache;
 
-       private GuavaObjectCacheFactory() {
-               // FIXME: make this more dynamic
-               this.cache = new GuavaObjectCache(queue, null);
-       }
+    private GuavaObjectCacheFactory() {
+        // FIXME: make this more dynamic using a spec
+        this.cache = new GuavaObjectCache(queue);
+    }
 
-       @Override
-       public void finalize() throws Throwable {
-               try {
-                       queue.close();
-               } finally {
-                       super.finalize();
-               }
-       }
+    @Override
+    public ObjectCache getObjectCache(final Class<?> objClass) {
+        return cache;
+    }
 
-       @Override
-       public ObjectCache getObjectCache(final Class<?> objClass) {
-               return cache;
-       }
+    @Override
+    public void close() {
+       queue.close();
+    }
 
-       public static GuavaObjectCacheFactory getInstance() {
-               return INSTANCE;
-       }
+    public static GuavaObjectCacheFactory getInstance() {
+        return INSTANCE;
+    }
 }