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

    • 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.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 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
    • 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> 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 cache
        dataBroker - the DataBroker
        datastoreType - the LogicalDatastoreType
        listenerRegistrationPath - the yang path for which register the listener
        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
    • 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)