Bug 735 - Part 1: Update ietf-restconf and ietf-yangtypes to newer versions
[yangtools.git] / common / object-cache-guava / src / main / java / org / opendaylight / yangtools / objcache / guava / GuavaObjectCacheFactory.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.objcache.guava;
9
10 import org.opendaylight.yangtools.objcache.ObjectCache;
11 import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
12
13 import com.google.common.base.FinalizableReferenceQueue;
14
15 public final class GuavaObjectCacheFactory implements IObjectCacheFactory {
16         private static final GuavaObjectCacheFactory INSTANCE = new GuavaObjectCacheFactory();
17         private final FinalizableReferenceQueue queue = new FinalizableReferenceQueue();
18         private final ObjectCache cache;
19
20         private GuavaObjectCacheFactory() {
21                 // FIXME: make this more dynamic
22                 this.cache = new GuavaObjectCache(queue, null);
23         }
24
25         @Override
26         public void finalize() throws Throwable {
27                 try {
28                         queue.close();
29                 } finally {
30                         super.finalize();
31                 }
32         }
33
34         @Override
35         public ObjectCache getObjectCache(final Class<?> objClass) {
36                 return cache;
37         }
38
39         public static GuavaObjectCacheFactory getInstance() {
40                 return INSTANCE;
41         }
42 }