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.BindingObject;
19 * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext} to which cache is
22 abstract class AbstractBindingNormalizedNodeCacheHolder {
23 private final LoadingCache<DataContainerCodecContext<?, ?>, DataObjectNormalizedNodeCache> caches = CacheBuilder
24 .newBuilder().build(new CacheLoader<DataContainerCodecContext<?, ?>, DataObjectNormalizedNodeCache>() {
26 public DataObjectNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) {
27 return new DataObjectNormalizedNodeCache(AbstractBindingNormalizedNodeCacheHolder.this, key);
30 private final ImmutableSet<Class<? extends BindingObject>> cacheSpec;
32 AbstractBindingNormalizedNodeCacheHolder(final ImmutableSet<Class<? extends BindingObject>> cacheSpec) {
33 this.cacheSpec = requireNonNull(cacheSpec);
36 DataObjectNormalizedNodeCache getCachingSerializer(final DataContainerCodecContext<?, ?> childCtx) {
37 if (isCached(childCtx.getBindingClass())) {
38 return caches.getUnchecked(childCtx);
43 final boolean isCached(final Class<? extends BindingObject> type) {
44 return cacheSpec.contains(type);