2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.objcache;
10 import static java.util.Objects.requireNonNull;
12 import javax.annotation.Nonnull;
13 import javax.annotation.concurrent.GuardedBy;
14 import org.opendaylight.yangtools.objcache.impl.StaticObjectCacheBinder;
15 import org.opendaylight.yangtools.objcache.spi.IObjectCacheFactory;
16 import org.opendaylight.yangtools.objcache.spi.NoopObjectCacheBinder;
19 * Point of entry for acquiring an {@link ObjectCache} instance.
21 public final class ObjectCacheFactory {
22 private static volatile IObjectCacheFactory factory;
24 private ObjectCacheFactory() {
25 throw new UnsupportedOperationException("Utility class should not be instantiated");
29 private static synchronized IObjectCacheFactory initialize() {
30 // Double-check under lock
31 IObjectCacheFactory fa = factory;
37 fa = StaticObjectCacheBinder.getInstance().getProductCacheFactory();
39 } catch (NoClassDefFoundError e) {
40 fa = NoopObjectCacheBinder.INSTANCE.getProductCacheFactory();
46 public static synchronized void reset() {
51 * Get an ObjectCache for caching a particular object class. Note
52 * that it may be shared for multiple classes.
54 * @param objClass Class of objects which are to be cached
55 * @return Object cache instance.
57 public static ObjectCache getObjectCache(@Nonnull final Class<?> objClass) {
58 IObjectCacheFactory fa = factory;
63 return fa.getObjectCache(requireNonNull(objClass));