Class RepositoryCache
- java.lang.Object
-
- org.eclipse.jgit.lib.RepositoryCache
-
public class RepositoryCache extends java.lang.Object
Cache of activeRepository
instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RepositoryCache.FileKey
Location of a Repository, using the standard java.io.File API.static interface
RepositoryCache.Key
Abstract hash key forRepositoryCache
entries.private static class
RepositoryCache.Lock
-
Field Summary
Fields Modifier and Type Field Description private static RepositoryCache
cache
private java.util.Map<RepositoryCache.Key,Repository>
cacheMap
private java.util.concurrent.ScheduledFuture<?>
cleanupTask
private long
expireAfter
private static org.slf4j.Logger
LOG
private RepositoryCache.Lock[]
openLocks
private java.lang.Object
schedulerLock
-
Constructor Summary
Constructors Modifier Constructor Description private
RepositoryCache()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
cache
private static final RepositoryCache cache
-
cacheMap
private final java.util.Map<RepositoryCache.Key,Repository> cacheMap
-
openLocks
private final RepositoryCache.Lock[] openLocks
-
cleanupTask
private java.util.concurrent.ScheduledFuture<?> cleanupTask
-
expireAfter
private volatile long expireAfter
-
schedulerLock
private final java.lang.Object schedulerLock
-
-
Method Detail
-
open
public static Repository open(RepositoryCache.Key location) throws java.io.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:
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.
-
open
public static Repository open(RepositoryCache.Key location, boolean mustExist) throws java.io.IOException
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:
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 ifmustExist
is true.
-
register
public static void register(Repository db)
Register one repository into the cache.During registration the cache automatically increments the usage counter, permitting it to retain the reference. A
RepositoryCache.FileKey
for 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
public static void close(@NonNull Repository db)
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
public static void unregister(Repository db)
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
public static void unregister(RepositoryCache.Key location)
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
public static java.util.Collection<RepositoryCache.Key> 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
static boolean isCached(@NonNull Repository repo)
-
clear
public static void clear()
Unregister all repositories from the cache.
-
clearExpired
static void clearExpired()
-
reconfigure
static void reconfigure(RepositoryCacheConfig repositoryCacheConfig)
-
configureEviction
private void configureEviction(RepositoryCacheConfig repositoryCacheConfig)
-
openRepository
private Repository openRepository(RepositoryCache.Key location, boolean mustExist) throws java.io.IOException
- Throws:
java.io.IOException
-
registerRepository
private void registerRepository(RepositoryCache.Key location, Repository db)
-
unregisterRepository
private Repository unregisterRepository(RepositoryCache.Key location)
-
isExpired
private boolean isExpired(Repository db)
-
unregisterAndCloseRepository
private void unregisterAndCloseRepository(RepositoryCache.Key location)
-
getKeys
private java.util.Collection<RepositoryCache.Key> getKeys()
-
clearAllExpired
private void clearAllExpired()
-
clearAll
private void clearAll()
-
lockFor
private RepositoryCache.Lock lockFor(RepositoryCache.Key location)
-
-