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;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
20 * Abstract Holder of Binding to Normalized Node caches indexed by {@link DataContainerCodecContext} to which cache is
23 abstract class AbstractBindingNormalizedNodeCacheHolder {
24 private final LoadingCache<DataContainerCodecContext<?, ?>, DataObjectNormalizedNodeCache> caches = CacheBuilder
25 .newBuilder().build(new CacheLoader<DataContainerCodecContext<?, ?>, DataObjectNormalizedNodeCache>() {
27 public DataObjectNormalizedNodeCache load(final DataContainerCodecContext<?, ?> key) {
28 return new DataObjectNormalizedNodeCache(AbstractBindingNormalizedNodeCacheHolder.this, key);
31 private final ImmutableSet<Class<? extends DataObject>> cacheSpec;
33 AbstractBindingNormalizedNodeCacheHolder(final ImmutableSet<Class<? extends DataObject>> cacheSpec) {
34 this.cacheSpec = requireNonNull(cacheSpec);
37 DataObjectNormalizedNodeCache getCachingSerializer(final DataContainerCodecContext<?, ?> childCtx) {
38 if (isCached(childCtx.getBindingClass())) {
39 return caches.getUnchecked(childCtx);
44 final boolean isCached(final Class<? extends BindingObject> type) {
45 return cacheSpec.contains(type);