Class RepositoryCache
Repository instances.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLocation of a Repository, using the standard java.io.File API.static interfaceAbstract hash key forRepositoryCacheentries.private static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final RepositoryCacheprivate final Map<RepositoryCache.Key,Repository> private ScheduledFuture<?>private longprivate static final org.slf4j.Loggerprivate final RepositoryCache.Lock[]private final Object -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Unregister all repositories from the cache.private voidclearAll()private void(package private) static voidstatic voidclose(Repository db) Close and remove a repository from the cache.private voidconfigureEviction(RepositoryCacheConfig repositoryCacheConfig) private Collection<RepositoryCache.Key>getKeys()static Collection<RepositoryCache.Key>Get the locations of all repositories registered in the cache.(package private) static booleanisCached(Repository repo) private booleanisExpired(Repository db) private RepositoryCache.LocklockFor(RepositoryCache.Key location) static Repositoryopen(RepositoryCache.Key location) Open an existing repository, reusing a cached instance if possible.static Repositoryopen(RepositoryCache.Key location, boolean mustExist) Open a repository, reusing a cached instance if possible.private RepositoryopenRepository(RepositoryCache.Key location, boolean mustExist) (package private) static voidreconfigure(RepositoryCacheConfig repositoryCacheConfig) static voidregister(Repository db) Register one repository into the cache.private voidregisterRepository(RepositoryCache.Key location, Repository db) static voidunregister(Repository db) Remove a repository from the cache.static voidunregister(RepositoryCache.Key location) Remove a repository from the cache.private voidprivate RepositoryunregisterRepository(RepositoryCache.Key location)
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
cache
-
cacheMap
-
openLocks
-
cleanupTask
-
expireAfter
private volatile long expireAfter -
schedulerLock
-
-
Constructor Details
-
RepositoryCache
private RepositoryCache()
-
-
Method Details
-
open
public static Repository open(RepositoryCache.Key location) throws IOException, RepositoryNotFoundException Open an existing repository, reusing a cached instance if possible.When done with the repository, the caller must call
Repository.close()to decrement the repository's usage counter.- Parameters:
location- where the local repository is. Typically aRepositoryCache.FileKey.- Returns:
- the repository instance requested; caller must close when done.
- Throws:
IOException- the repository could not be read (likely its core.version property is not supported).RepositoryNotFoundException- there is no repository at the given location.
-
open
Open a repository, reusing a cached instance if possible.When done with the repository, the caller must call
Repository.close()to decrement the repository's usage counter.- Parameters:
location- where the local repository is. Typically aRepositoryCache.FileKey.mustExist- If true, and the repository is not found, throwsRepositoryNotFoundException. If false, a repository instance is created and registered anyway.- Returns:
- the repository instance requested; caller must close when done.
- Throws:
IOException- the repository could not be read (likely its core.version property is not supported).RepositoryNotFoundException- There is no repository at the given location, only thrown ifmustExistis true.
-
register
Register one repository into the cache.During registration the cache automatically increments the usage counter, permitting it to retain the reference. A
RepositoryCache.FileKeyfor the repository'sRepository.getDirectory()is used to index the repository in the cache.If another repository already is registered in the cache at this location, the other instance is closed.
- Parameters:
db- repository to register.
-
close
Close and remove a repository from the cache.Removes a repository from the cache, if it is still registered here, and close it.
- Parameters:
db- repository to unregister.
-
unregister
Remove a repository from the cache.Removes a repository from the cache, if it is still registered here. This method will not close the repository, only remove it from the cache. See
close(Repository)to remove and close the repository.- Parameters:
db- repository to unregister.- Since:
- 4.3
-
unregister
Remove a repository from the cache.Removes a repository from the cache, if it is still registered here. This method will not close the repository, only remove it from the cache. See
close(Repository)to remove and close the repository.- Parameters:
location- location of the repository to remove.- Since:
- 4.1
-
getRegisteredKeys
Get the locations of all repositories registered in the cache.- Returns:
- the locations of all repositories registered in the cache.
- Since:
- 4.1
-
isCached
-
clear
public static void clear()Unregister all repositories from the cache. -
clearExpired
static void clearExpired() -
reconfigure
-
configureEviction
-
openRepository
private Repository openRepository(RepositoryCache.Key location, boolean mustExist) throws IOException - Throws:
IOException
-
registerRepository
-
unregisterRepository
-
isExpired
-
unregisterAndCloseRepository
-
getKeys
-
clearAllExpired
private void clearAllExpired() -
clearAll
private void clearAll() -
lockFor
-