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 static java.util.Objects.requireNonNull;
12 import com.google.common.cache.CacheBuilder;
13 import com.google.common.cache.CacheLoader;
14 import com.google.common.cache.LoadingCache;
15 import com.google.common.collect.ImmutableSet;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
19 * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext} to which cache is
22 abstract class AbstractBindingNormalizedNodeCacheHolder {
24 private final ImmutableSet<Class<? extends DataObject>> cachedValues;
25 private final LoadingCache<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache> caches = CacheBuilder
26 .newBuilder().build(new CacheLoader<DataContainerCodecContext<?, ?>, BindingNormalizedNodeCache>() {
28 public BindingNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) {
29 return new BindingNormalizedNodeCache(AbstractBindingNormalizedNodeCacheHolder.this, key);
33 AbstractBindingNormalizedNodeCacheHolder(final ImmutableSet<Class<? extends DataObject>> cacheSpec) {
34 cachedValues = requireNonNull(cacheSpec);
37 BindingNormalizedNodeCache getCachingSerializer(final DataContainerCodecContext<?, ?> childCtx) {
38 if (isCached(childCtx.getBindingClass())) {
39 return caches.getUnchecked(childCtx);
44 boolean isCached(final Class<?> type) {
45 return cachedValues.contains(type);