Class DataObjectCache<K,​V extends org.opendaylight.yangtools.yang.binding.DataObject>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener<V> dataObjectListener  
      protected org.opendaylight.yangtools.concepts.ListenerRegistration<?> listenerRegistration  
    • Constructor Summary

      Constructors 
      Constructor Description
      DataObjectCache​(java.lang.Class<V> dataObjectClass, org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, 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)  
      DataObjectCache​(java.lang.Class<V> dataObjectClass, org.opendaylight.mdsal.binding.api.DataBroker dataBroker, org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType, org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> listetenerRegistrationPath, 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 java.util.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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • listenerRegistration

        protected org.opendaylight.yangtools.concepts.ListenerRegistration<?> listenerRegistration
      • dataObjectListener

        protected org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener<V extends org.opendaylight.yangtools.yang.binding.DataObject> dataObjectListener
    • Constructor Detail

      • DataObjectCache

        public DataObjectCache​(java.lang.Class<V> dataObjectClass,
                               org.opendaylight.mdsal.binding.api.DataBroker dataBroker,
                               org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType,
                               org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> listetenerRegistrationPath,
                               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 cache
        dataBroker - the DataBroker
        datastoreType - the LogicalDatastoreType
        cacheProvider - the CacheProvider used to instantiate the Cache
        keyFunction - the function used to convert or extract the key instance on change notification
        instanceIdFunction - the function used to convert a key instance to an InstanceIdentifier on read
      • DataObjectCache

        public DataObjectCache​(java.lang.Class<V> dataObjectClass,
                               org.opendaylight.mdsal.binding.api.DataBroker dataBroker,
                               org.opendaylight.mdsal.common.api.LogicalDatastoreType datastoreType,
                               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)
    • Method Detail

      • close

        @PreDestroy
        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • checkIsClosed

        protected void checkIsClosed()
                              throws org.opendaylight.mdsal.common.api.ReadFailedException
        Throws:
        org.opendaylight.mdsal.common.api.ReadFailedException
      • get

        public @NonNull java.util.Optional<V> get​(@NonNull K key)
                                           throws org.opendaylight.mdsal.common.api.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.mdsal.common.api.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)
      • removed

        protected void removed​(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<V> path,
                               V dataObject)