public class RepositoryCache
extends java.lang.Object
Repository
instances.Modifier and Type | Class and Description |
---|---|
static class |
RepositoryCache.FileKey
Location of a Repository, using the standard java.io.File API.
|
static interface |
RepositoryCache.Key
Abstract hash key for
RepositoryCache entries. |
private static class |
RepositoryCache.Lock |
Modifier and Type | Field and Description |
---|---|
private static RepositoryCache |
cache |
private java.util.concurrent.ConcurrentHashMap<RepositoryCache.Key,Repository> |
cacheMap |
private java.util.concurrent.ScheduledFuture<?> |
cleanupTask |
private long |
expireAfter |
private static org.slf4j.Logger |
LOG |
private RepositoryCache.Lock[] |
openLocks |
Modifier | Constructor and Description |
---|---|
private |
RepositoryCache() |
Modifier and Type | Method and Description |
---|---|
static void |
clear()
Unregister all repositories from the cache.
|
private void |
clearAll() |
private void |
clearAllExpired() |
(package private) static void |
clearExpired() |
static void |
close(Repository db)
Close and remove a repository from the cache.
|
private void |
configureEviction(RepositoryCacheConfig repositoryCacheConfig) |
private java.util.Collection<RepositoryCache.Key> |
getKeys() |
static java.util.Collection<RepositoryCache.Key> |
getRegisteredKeys()
Get the locations of all repositories registered in the cache.
|
(package private) static boolean |
isCached(Repository repo) |
private boolean |
isExpired(Repository db) |
private RepositoryCache.Lock |
lockFor(RepositoryCache.Key location) |
static Repository |
open(RepositoryCache.Key location)
Open an existing repository, reusing a cached instance if possible.
|
static Repository |
open(RepositoryCache.Key location,
boolean mustExist)
Open a repository, reusing a cached instance if possible.
|
private Repository |
openRepository(RepositoryCache.Key location,
boolean mustExist) |
(package private) static void |
reconfigure(RepositoryCacheConfig repositoryCacheConfig) |
static void |
register(Repository db)
Register one repository into the cache.
|
private void |
registerRepository(RepositoryCache.Key location,
Repository db) |
static void |
unregister(Repository db)
Remove a repository from the cache.
|
static void |
unregister(RepositoryCache.Key location)
Remove a repository from the cache.
|
private void |
unregisterAndCloseRepository(RepositoryCache.Key location) |
private Repository |
unregisterRepository(RepositoryCache.Key location) |
private static final org.slf4j.Logger LOG
private static final RepositoryCache cache
private final java.util.concurrent.ConcurrentHashMap<RepositoryCache.Key,Repository> cacheMap
private final RepositoryCache.Lock[] openLocks
private java.util.concurrent.ScheduledFuture<?> cleanupTask
private volatile long expireAfter
public static Repository open(RepositoryCache.Key location) throws java.io.IOException, RepositoryNotFoundException
When done with the repository, the caller must call
Repository.close()
to decrement the
repository's usage counter.
location
- where the local repository is. Typically a
RepositoryCache.FileKey
.java.io.IOException
- the repository could not be read (likely its core.version
property is not supported).RepositoryNotFoundException
- there is no repository at the given location.public static Repository open(RepositoryCache.Key location, boolean mustExist) throws java.io.IOException
When done with the repository, the caller must call
Repository.close()
to decrement the
repository's usage counter.
location
- where the local repository is. Typically a
RepositoryCache.FileKey
.mustExist
- If true, and the repository is not found, throws RepositoryNotFoundException
. If false, a repository instance
is created and registered anyway.java.io.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 if
mustExist
is true.public static void register(Repository db)
During registration the cache automatically increments the usage counter,
permitting it to retain the reference. A
RepositoryCache.FileKey
for the repository's
Repository.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.
db
- repository to register.public static void close(@NonNull Repository db)
Removes a repository from the cache, if it is still registered here, and close it.
db
- repository to unregister.public static void unregister(Repository db)
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.
db
- repository to unregister.public static void unregister(RepositoryCache.Key location)
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.
location
- location of the repository to remove.public static java.util.Collection<RepositoryCache.Key> getRegisteredKeys()
static boolean isCached(@NonNull Repository repo)
public static void clear()
static void clearExpired()
static void reconfigure(RepositoryCacheConfig repositoryCacheConfig)
private void configureEviction(RepositoryCacheConfig repositoryCacheConfig)
private Repository openRepository(RepositoryCache.Key location, boolean mustExist) throws java.io.IOException
java.io.IOException
private void registerRepository(RepositoryCache.Key location, Repository db)
private Repository unregisterRepository(RepositoryCache.Key location)
private boolean isExpired(Repository db)
private void unregisterAndCloseRepository(RepositoryCache.Key location)
private java.util.Collection<RepositoryCache.Key> getKeys()
private void clearAllExpired()
private void clearAll()
private RepositoryCache.Lock lockFor(RepositoryCache.Key location)