Add support for EventInstantAware notifications
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / AbstractBindingLoadingAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14
15 @NonNullByDefault
16 abstract class AbstractBindingLoadingAdapter<D, K, V> extends AbstractBindingAdapter<D> {
17     private final LoadingCache<K, V> proxies = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<K, V>() {
18         @Override
19         public V load(final K key) {
20             return loadAdapter(key);
21         }
22     });
23
24     AbstractBindingLoadingAdapter(final BindingToNormalizedNodeCodec codec, final D delegate) {
25         super(codec, delegate);
26     }
27
28     final V getAdapter(final K key) {
29         return proxies.getUnchecked(key);
30     }
31
32     abstract V loadAdapter(K key);
33 }