*/
package org.opendaylight.yangtools.objcache;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
-
import org.opendaylight.yangtools.objcache.impl.StaticObjectCacheBinder;
import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
import org.opendaylight.yangtools.objcache.spi.NoopObjectCacheBinder;
public final class ObjectCacheFactory {
private static volatile IObjectCacheFactory factory;
+ private ObjectCacheFactory() {
+ throw new UnsupportedOperationException("Utility class should not be instantiated");
+ }
+
@GuardedBy("this")
private static synchronized IObjectCacheFactory initialize() {
// Double-check under lock
- IObjectCacheFactory f = factory;
- if (f != null) {
- return f;
+ IObjectCacheFactory fa = factory;
+ if (fa != null) {
+ return fa;
}
try {
- f = StaticObjectCacheBinder.getInstance().getProductCacheFactory();
- factory = f;
+ fa = StaticObjectCacheBinder.getInstance().getProductCacheFactory();
+ factory = fa;
} catch (NoClassDefFoundError e) {
- f = NoopObjectCacheBinder.INSTANCE.getProductCacheFactory();
+ fa = NoopObjectCacheBinder.INSTANCE.getProductCacheFactory();
}
- return f;
+ return fa;
}
public static synchronized void reset() {
* @return Object cache instance.
*/
public static ObjectCache getObjectCache(@Nonnull final Class<?> objClass) {
- IObjectCacheFactory f = factory;
- if (f == null) {
- f = initialize();
+ IObjectCacheFactory fa = factory;
+ if (fa == null) {
+ fa = initialize();
}
- return f.getObjectCache(Preconditions.checkNotNull(objClass));
+ return fa.getObjectCache(requireNonNull(objClass));
}
}