Class CachingPersistenceManagerProxy

java.lang.Object
org.apache.felix.cm.impl.persistence.CachingPersistenceManagerProxy
All Implemented Interfaces:
ExtPersistenceManager, PersistenceManager

public class CachingPersistenceManagerProxy extends Object implements ExtPersistenceManager
The CachingPersistenceManagerProxy adds a caching layer to the underlying actual PersistenceManager implementation. All API calls are also (or primarily) routed through a local cache of dictionaries indexed by the service.pid.
  • Constructor Details

  • Method Details

    • getDelegatee

      public PersistenceManager getDelegatee()
      Specified by:
      getDelegatee in interface ExtPersistenceManager
    • delete

      public void delete(String pid) throws IOException
      Remove the configuration with the given PID. This implementation removes the entry from the cache before calling the underlying persistence manager.
      Specified by:
      delete in interface PersistenceManager
      Parameters:
      pid - The identifier of the dictionary to delete.
      Throws:
      IOException - If an error occurs deleting the dictionary. This exception must not be thrown if no dictionary with the given identifier exists.
    • exists

      public boolean exists(String pid)
      Checks whether a dictionary with the given pid exists. First checks for the existence in the cache. If not in the cache the underlying persistence manager is asked.
      Specified by:
      exists in interface PersistenceManager
      Parameters:
      pid - The identifier for the dictionary to test.
      Returns:
      true if a persisted dictionary exists for the pid.
    • getDictionaries

      public Enumeration getDictionaries() throws IOException
      Returns an Enumeration of Dictionary objects representing the configurations stored in the underlying persistence managers. The dictionaries returned are guaranteed to contain the service.pid property.

      Note, that each call to this method will return new dictionary objects. That is modifying the contents of a dictionary returned from this method has no influence on the dictionaries stored in the cache.

      Specified by:
      getDictionaries in interface PersistenceManager
      Returns:
      A possibly empty Enumeration of all dictionaries.
      Throws:
      IOException - If an error occurs getting the dictionaries.
    • getDictionaries

      public Collection<Dictionary> getDictionaries(org.apache.felix.cm.impl.SimpleFilter filter) throws IOException
      Specified by:
      getDictionaries in interface ExtPersistenceManager
      Throws:
      IOException
    • load

      public Dictionary load(String pid) throws IOException
      Returns the dictionary for the given PID or null if no such dictionary is stored by the underlying persistence manager. This method caches the returned dictionary for future use after retrieving if from the persistence manager.

      Note, that each call to this method will return new dictionary instance. That is modifying the contents of a dictionary returned from this method has no influence on the dictionaries stored in the cache.

      Specified by:
      load in interface PersistenceManager
      Parameters:
      pid - The identifier for the dictionary to load.
      Returns:
      The dictionary for the identifier. This must not be null but may be empty.
      Throws:
      IOException - If an error occurs loading the dictionary. An IOException must also be thrown if no dictionary exists for the given identifier.
    • store

      public void store(String pid, Dictionary properties) throws IOException
      Stores the dictionary in the cache and in the underlying persistence manager. This method first calls the underlying persistence manager before updating the dictionary in the cache.

      Note, that actually a copy of the dictionary is stored in the cache. That is subsequent modification to the given dictionary has no influence on the cached data.

      Specified by:
      store in interface PersistenceManager
      Parameters:
      pid - The identifier of the dictionary.
      properties - The Dictionary to store.
      Throws:
      IOException - If an error occurs storing the dictionary. If this exception is thrown, it is expected, that exists(pid returns false.
    • getFactoryConfigurationPids

      public Set<String> getFactoryConfigurationPids(List<String> targetedFactoryPids) throws IOException
      Specified by:
      getFactoryConfigurationPids in interface ExtPersistenceManager
      Throws:
      IOException