import org.opendaylight.yangtools.objcache.impl.StaticObjectCacheBinder;
import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
+import org.opendaylight.yangtools.objcache.spi.NoopObjectCacheBinder;
import com.google.common.base.Preconditions;
* Point of entry for acquiring an {@link ObjectCache} instance.
*/
public final class ObjectCacheFactory {
- private static IObjectCacheFactory FACTORY;
-
- private static synchronized IObjectCacheFactory initialize() {
- // Double-check under lock
- if (FACTORY != null) {
- return FACTORY;
- }
-
- final IObjectCacheFactory f = StaticObjectCacheBinder.getInstance().getProductCacheFactory();
- FACTORY = f;
- return f;
- }
-
- public static synchronized void reset() {
- FACTORY = null;
- }
-
- /**
- * Get an ObjectCache for caching a particular object class. Note
- * that it may be shared for multiple classes.
- *
- * @param objClass Class of objects which are to be cached
- * @return Object cache instance.
- */
- public static ObjectCache getObjectCache(@Nonnull final Class<?> objClass) {
- IObjectCacheFactory f = FACTORY;
- if (f == null) {
- f = initialize();
- }
-
- return f.getObjectCache(Preconditions.checkNotNull(objClass));
- }
+ private static IObjectCacheFactory FACTORY;
+
+ private static synchronized IObjectCacheFactory initialize() {
+ // Double-check under lock
+ if (FACTORY != null) {
+ return FACTORY;
+ }
+
+ IObjectCacheFactory f;
+ try {
+ f = StaticObjectCacheBinder.getInstance().getProductCacheFactory();
+ FACTORY = f;
+ } catch (NoClassDefFoundError e) {
+ f = NoopObjectCacheBinder.INSTANCE.getProductCacheFactory();
+ }
+
+ return f;
+ }
+
+ public static synchronized void reset() {
+ FACTORY = null;
+ }
+
+ /**
+ * Get an ObjectCache for caching a particular object class. Note
+ * that it may be shared for multiple classes.
+ *
+ * @param objClass Class of objects which are to be cached
+ * @return Object cache instance.
+ */
+ public static ObjectCache getObjectCache(@Nonnull final Class<?> objClass) {
+ IObjectCacheFactory f = FACTORY;
+ if (f == null) {
+ f = initialize();
+ }
+
+ return f.getObjectCache(Preconditions.checkNotNull(objClass));
+ }
}