Class ReferenceCache
java.lang.Object
org.splevo.jamopp.extraction.cache.ReferenceCache
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
-
Constructor Summary
ConstructorDescriptionReferenceCache
(List<String> cacheFileDirectories) Constructor to set a list of directories containing cache files. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Check is already present in the cached.void
registerEObject
(Resource resource, String fragmentURI, EObject resolvedElement) Register a resolvedEObject
to the cache which has been resolved by EMF without involving the cache.void
Resets the cache for the given resource and saves the cache afterwards to prevent old entries from appearing after loading the resource again.void
Forces the complete resolving of the resource.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.void
save
(File cacheFile, ReferenceCacheData cacheData) Persist the cache in the file system.
-
Field Details
-
CACHE_FILE_NAME
The name of the cache files to be used.- See Also:
-
-
Constructor Details
-
ReferenceCache
Constructor to set a list of directories containing cache files. Within these directories, files with the nameCACHE_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
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
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
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
Check is already present in the cached.- Parameters:
resource
- The resource to check for.- Returns:
- True/ False if it is cached or not.
-
registerEObject
Register a resolvedEObject
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 / referencefragmentURI
- The fragmentURI if the proxyresolvedElement
- The resolved element
-
reset
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
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.
-