|
|
@ -130,10 +130,10 @@ public class RepositoryCache { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Remove a repository from the cache. |
|
|
|
* Close and remove a repository from the cache. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* Removes a repository from the cache, if it is still registered here, |
|
|
|
* Removes a repository from the cache, if it is still registered here, and |
|
|
|
* permitting it to close. |
|
|
|
* close it. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param db |
|
|
|
* @param db |
|
|
|
* repository to unregister. |
|
|
|
* repository to unregister. |
|
|
@ -141,15 +141,35 @@ public class RepositoryCache { |
|
|
|
public static void close(final Repository db) { |
|
|
|
public static void close(final Repository db) { |
|
|
|
if (db.getDirectory() != null) { |
|
|
|
if (db.getDirectory() != null) { |
|
|
|
FileKey key = FileKey.exact(db.getDirectory(), db.getFS()); |
|
|
|
FileKey key = FileKey.exact(db.getDirectory(), db.getFS()); |
|
|
|
cache.unregisterRepository(key); |
|
|
|
cache.unregisterAndCloseRepository(key); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Remove a repository from the cache. |
|
|
|
* Remove a repository from the cache. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* Removes a repository from the cache, if it is still registered here, |
|
|
|
* Removes a repository from the cache, if it is still registered here. This |
|
|
|
* permitting it to close. |
|
|
|
* method will not close the repository, only remove it from the cache. See |
|
|
|
|
|
|
|
* {@link RepositoryCache#close(Repository)} to remove and close the |
|
|
|
|
|
|
|
* repository. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param db |
|
|
|
|
|
|
|
* repository to unregister. |
|
|
|
|
|
|
|
* @since 4.3 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static void unregister(final Repository db) { |
|
|
|
|
|
|
|
if (db.getDirectory() != null) { |
|
|
|
|
|
|
|
unregister(FileKey.exact(db.getDirectory(), db.getFS())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Remove a repository from the cache. |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* 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 |
|
|
|
|
|
|
|
* {@link RepositoryCache#close(Repository)} to remove and close the |
|
|
|
|
|
|
|
* repository. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param location |
|
|
|
* @param location |
|
|
|
* location of the repository to remove. |
|
|
|
* location of the repository to remove. |
|
|
@ -196,15 +216,17 @@ public class RepositoryCache { |
|
|
|
db = location.open(mustExist); |
|
|
|
db = location.open(mustExist); |
|
|
|
ref = new SoftReference<Repository>(db); |
|
|
|
ref = new SoftReference<Repository>(db); |
|
|
|
cacheMap.put(location, ref); |
|
|
|
cacheMap.put(location, ref); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
db.incrementOpen(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
db.incrementOpen(); |
|
|
|
db.incrementOpen(); |
|
|
|
|
|
|
|
} |
|
|
|
return db; |
|
|
|
return db; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void registerRepository(final Key location, final Repository db) { |
|
|
|
private void registerRepository(final Key location, final Repository db) { |
|
|
|
db.incrementOpen(); |
|
|
|
|
|
|
|
SoftReference<Repository> newRef = new SoftReference<Repository>(db); |
|
|
|
SoftReference<Repository> newRef = new SoftReference<Repository>(db); |
|
|
|
Reference<Repository> oldRef = cacheMap.put(location, newRef); |
|
|
|
Reference<Repository> oldRef = cacheMap.put(location, newRef); |
|
|
|
Repository oldDb = oldRef != null ? oldRef.get() : null; |
|
|
|
Repository oldDb = oldRef != null ? oldRef.get() : null; |
|
|
@ -212,12 +234,17 @@ public class RepositoryCache { |
|
|
|
oldDb.close(); |
|
|
|
oldDb.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void unregisterRepository(final Key location) { |
|
|
|
private Repository unregisterRepository(final Key location) { |
|
|
|
Reference<Repository> oldRef = cacheMap.remove(location); |
|
|
|
Reference<Repository> oldRef = cacheMap.remove(location); |
|
|
|
Repository oldDb = oldRef != null ? oldRef.get() : null; |
|
|
|
return oldRef != null ? oldRef.get() : null; |
|
|
|
if (oldDb != null) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void unregisterAndCloseRepository(final Key location) { |
|
|
|
|
|
|
|
Repository oldDb = unregisterRepository(location); |
|
|
|
|
|
|
|
if (oldDb != null) { |
|
|
|
oldDb.close(); |
|
|
|
oldDb.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Collection<Key> getKeys() { |
|
|
|
private Collection<Key> getKeys() { |
|
|
|
return new ArrayList<Key>(cacheMap.keySet()); |
|
|
|
return new ArrayList<Key>(cacheMap.keySet()); |
|
|
|