2 * Copyright (c) 2015 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.mdsal.binding.dom.codec.impl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.cache.CacheBuilder;
12 import com.google.common.cache.CacheLoader;
13 import com.google.common.cache.LoadingCache;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
18 * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext} to which cache is
21 abstract class AbstractBindingNormalizedNodeCacheHolder {
23 private final Set<Class<? extends DataObject>> cachedValues;
24 private final LoadingCache<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache> caches = CacheBuilder
25 .newBuilder().build(new CacheLoader<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache>() {
27 public BindingNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) {
28 return new BindingNormalizedNodeCache(AbstractBindingNormalizedNodeCacheHolder.this, key);
32 protected AbstractBindingNormalizedNodeCacheHolder(final Set<Class<? extends DataObject>> cacheSpec) {
33 cachedValues = Preconditions.checkNotNull(cacheSpec);
36 BindingNormalizedNodeCache getCachingSerializer(final DataContainerCodecContext<?, ?> childCtx) {
37 if (isCached(childCtx.getBindingClass())) {
38 return caches.getUnchecked(childCtx);
43 boolean isCached(final Class<?> type) {
44 return cachedValues.contains(type);