Class DataObjectCache<K,V extends org.opendaylight.yangtools.yang.binding.DataObject>
- java.lang.Object
-
- org.opendaylight.genius.mdsalutil.cache.DataObjectCache<K,V>
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
DpnTepStateCache
,IfIndexInterfaceCache
,InstanceIdDataObjectCache
,OvsBridgeEntryCache
,OvsBridgeRefEntryCache
public class DataObjectCache<K,V extends org.opendaylight.yangtools.yang.binding.DataObject> extends java.lang.Object implements java.lang.AutoCloseable
Caches DataObjects of a particular type. The cache is updated by a DataTreeChangeListener.- Author:
- Thomas Pantelis
-
-
Constructor Summary
Constructors Constructor Description DataObjectCache(java.lang.Class<V> dataObjectClass, org.opendaylight.controller.md.sal.binding.api.DataBroker dataBroker, org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> listenerRegistrationPath, org.opendaylight.infrautils.caches.CacheProvider cacheProvider, java.util.function.BiFunction<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V>,V,K> keyFunction, java.util.function.Function<K,org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V>> instanceIdFunction)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
added(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> path, V dataObject)
protected void
checkIsClosed()
void
close()
@NonNull com.google.common.base.Optional<V>
get(@NonNull K key)
Gets the DataObject for the given key.@NonNull java.util.Collection<V>
getAllPresent()
Gets all DataObjects currently in the cache.protected void
removed(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> path, V dataObject)
-
-
-
Constructor Detail
-
DataObjectCache
public DataObjectCache(java.lang.Class<V> dataObjectClass, org.opendaylight.controller.md.sal.binding.api.DataBroker dataBroker, org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> listenerRegistrationPath, org.opendaylight.infrautils.caches.CacheProvider cacheProvider, java.util.function.BiFunction<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V>,V,K> keyFunction, java.util.function.Function<K,org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V>> instanceIdFunction)
Constructor.- Parameters:
dataObjectClass
- the DataObject class to cachedataBroker
- the DataBrokerdatastoreType
- the LogicalDatastoreTypelistenerRegistrationPath
- the yang path for which register the listenercacheProvider
- the CacheProvider used to instantiate the CachekeyFunction
- the function used to convert or extract the key instance on change notificationinstanceIdFunction
- the function used to convert a key instance to an InstanceIdentifier on read
-
-
Method Detail
-
close
@PreDestroy public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
checkIsClosed
protected void checkIsClosed() throws org.opendaylight.controller.md.sal.common.api.data.ReadFailedException
- Throws:
org.opendaylight.controller.md.sal.common.api.data.ReadFailedException
-
get
public @NonNull com.google.common.base.Optional<V> get(@NonNull K key) throws org.opendaylight.controller.md.sal.common.api.data.ReadFailedException
Gets the DataObject for the given key. If there's no DataObject cached, it will be read from the data store and put in the cache if it exists.- Parameters:
key
- identifies the DataObject to query- Returns:
- if the data for the supplied key exists, returns an Optional object containing the data; otherwise, returns Optional#absent()
- Throws:
org.opendaylight.controller.md.sal.common.api.data.ReadFailedException
- if that data isn't cached and the read to fetch it fails
-
getAllPresent
public @NonNull java.util.Collection<V> getAllPresent()
Gets all DataObjects currently in the cache.- Returns:
- the DataObjects currently in the cache
-
added
protected void added(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> path, V dataObject)
-
-