Class ReferenceCache

java.lang.Object
org.splevo.jamopp.extraction.cache.ReferenceCache

public class ReferenceCache extends Object
A file based cache to reuse the proxy resolutions already performed. The cache was designed to work with one or more cache files to use it with resource sets containing the resources of one or more software models. For example, during extraction a separate resource set is used per software, but for differencing several software models must be accessed in one resource set. Cache files are always named according to CACHE_FILE_NAME. During initialization, cache files existing in the provided directories are loaded. Subdirectories are not considered. When proxies in new resources are resolved and save() is triggered, they are stored in a cache file of the first directory provided in the list. If a cache file already exists in the first cache directory, the existing cache is loaded and enhanced with the new cached references.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the cache files to be used.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReferenceCache(List<String> cacheFileDirectories)
    Constructor to set a list of directories containing cache files.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    blacklist(Resource resource)
    Blacklists the given resource by its URI.
    getEObject(Resource resource, String id)
    Resolve a specific proxy referenced in resource.
    int
    Get the internal counter how many references have not been resolved from cache, while their resources have.
    boolean
    isCached(Resource resource)
    Check is already present in the cached.
    void
    registerEObject(Resource resource, String fragmentURI, EObject resolvedElement)
    Register a resolved EObject to the cache which has been resolved by EMF without involving the cache.
    void
    reset(Resource resource)
    Resets the cache for the given resource and saves the cache afterwards to prevent old entries from appearing after loading the resource again.
    void
    resolve(Resource resource)
    Forces the complete resolving of the resource.
    void
    Trigger to save all non yet persisted cache entries.
    These are the entries created for resources that could not be loaded from any existing cache file.
    void
    save(File cacheFile, ReferenceCacheData cacheData)
    Persist the cache in the file system.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • ReferenceCache

      public ReferenceCache(List<String> cacheFileDirectories)
      Constructor to set a list of directories containing cache files. Within these directories, files with the name CACHE_FILE_NAME are searched. If a new file must be created, this will be done in the first directory of the list.
      Parameters:
      cacheFileDirectories - A list of absolute paths to the directories containing cache files.
  • Method Details

    • resolve

      public void resolve(Resource resource)
      Forces the complete resolving of the resource.

      Note: This should be used for loading the cache only. It is also recommended to call this method not before all resources are present in the ResourceSet.

      Parameters:
      resource - Resource to be resolved.
    • save

      public void save()
      Trigger to save all non yet persisted cache entries.
      These are the entries created for resources that could not be loaded from any existing cache file. If more than one cache file directory was created, the first entry in the list will be used. If the cache file already exists, it will not be overridden, but loaded and the new entries will be added to it.
    • save

      public void save(File cacheFile, ReferenceCacheData cacheData)
      Persist the cache in the file system.
      Parameters:
      cacheFile - The file to save to.
      cacheData - The cache data to save.
    • getNotResolvedFromCacheCounterReference

      public int getNotResolvedFromCacheCounterReference()
      Get the internal counter how many references have not been resolved from cache, while their resources have. This is an indicator for failed proxy resolutions or that the cache was not involved in the resolution.
      Returns:
      The counter value.
    • getEObject

      public EObject getEObject(Resource resource, String id)
      Resolve a specific proxy referenced in resource.
      Parameters:
      resource - The resource containing the proxy.
      id - The id (local fragment uri) of the proxy.
      Returns:
      The object resolved for the id.
    • isCached

      public boolean isCached(Resource resource)
      Check is already present in the cached.
      Parameters:
      resource - The resource to check for.
      Returns:
      True/ False if it is cached or not.
    • registerEObject

      public void registerEObject(Resource resource, String fragmentURI, EObject resolvedElement)
      Register a resolved EObject to the cache which has been resolved by EMF without involving the cache. E.g. by indirectly resolving it without participating the cache.
      Parameters:
      resource - The resource containing the proxy / reference
      fragmentURI - The fragmentURI if the proxy
      resolvedElement - The resolved element
    • reset

      public void reset(Resource resource)
      Resets the cache for the given resource and saves the cache afterwards to prevent old entries from appearing after loading the resource again.
      Parameters:
      resource - The resource for which the cache shall be reset.
    • blacklist

      public void blacklist(Resource resource)
      Blacklists the given resource by its URI. The cache will ignore any attempts to set a cache line involving the given resource.
      Parameters:
      resource - The resource to be blacklisted.