public boolean deletePendingFederationProposal(FederationProposal proposal) {
return federationManager.deletePendingFederationProposal(proposal);
}
+
+ @Override
+ public void closeAll() {
+ repositoryManager.closeAll();
+ }
+
+ @Override
+ public void close(String repository) {
+ repositoryManager.close(repository);
+ }
+
+ @Override
+ public boolean isIdle(Repository repository) {
+ return repositoryManager.isIdle(repository);
+ }
}
*/
boolean isCollectingGarbage(String repositoryName);
+ /**
+ * Ensures that all cached repositories are completely closed and their resources
+ * are properly released.
+ */
+ void closeAll();
+
+ /**
+ * Ensures that a cached repository is completely closed and it's resources
+ * are properly released.
+ */
+ void close(String repository);
+
+ /**
+ * Returns true if the repository is idle (not being accessed).
+ *
+ * @param repository
+ * @return true if the repository is idle
+ */
+ boolean isIdle(Repository repository);
}
\ No newline at end of file
gcExecutor.close();
mirrorExecutor.close();
+ closeAll();
return this;
}
return size;
}
+ /**
+ * Returns true if the repository is idle (not being accessed).
+ *
+ * @param repository
+ * @return true if the repository is idle
+ */
+ @Override
+ public boolean isIdle(Repository repository) {
+ try {
+ // Read the use count.
+ // An idle use count is 2:
+ // +1 for being in the cache
+ // +1 for the repository parameter in this method
+ Field useCnt = Repository.class.getDeclaredField("useCnt");
+ useCnt.setAccessible(true);
+ int useCount = ((AtomicInteger) useCnt.get(repository)).get();
+ return useCount == 2;
+ } catch (Exception e) {
+ logger.warn(MessageFormat
+ .format("Failed to reflectively determine use count for repository {0}",
+ repository.getDirectory().getPath()), e);
+ }
+ return false;
+ }
+
+ /**
+ * Ensures that all cached repository are completely closed and their resources
+ * are properly released.
+ */
+ @Override
+ public void closeAll() {
+ for (String repository : getRepositoryList()) {
+ close(repository);
+ }
+ }
+
/**
* Ensure that a cached repository is completely closed and its resources
* are properly released.
*
* @param repositoryName
*/
- private void closeRepository(String repositoryName) {
+ @Override
+ public void close(String repositoryName) {
Repository repository = getRepository(repositoryName);
if (repository == null) {
return;
repositoryName), e);
}
if (uses > 0) {
- logger.info(MessageFormat
+ logger.debug(MessageFormat
.format("{0}.useCnt={1}, calling close() {2} time(s) to close object and ref databases",
repositoryName, uses, uses));
for (int i = 0; i < uses; i++) {
"Failed to rename ''{0}'' because ''{1}'' already exists.",
repositoryName, repository.name));
}
- closeRepository(repositoryName);
+ close(repositoryName);
File folder = new File(repositoriesFolder, repositoryName);
File destFolder = new File(repositoriesFolder, repository.name);
if (destFolder.exists()) {
@Override
public boolean deleteRepository(String repositoryName) {
try {
- closeRepository(repositoryName);
+ close(repositoryName);
// clear the repository cache
clearRepositoryMetadataCache(repositoryName);
*/\r
package com.gitblit.service;\r
\r
-import java.lang.reflect.Field;\r
import java.text.MessageFormat;\r
import java.util.Calendar;\r
import java.util.Date;\r
import java.util.Properties;\r
import java.util.concurrent.ConcurrentHashMap;\r
import java.util.concurrent.atomic.AtomicBoolean;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
\r
import org.eclipse.jgit.api.GarbageCollectCommand;\r
import org.eclipse.jgit.api.Git;\r
\r
import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
-import com.gitblit.Keys.git;\r
import com.gitblit.manager.IRepositoryManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.FileUtils;\r
continue;\r
}\r
\r
- if (!isRepositoryIdle(repository)) {\r
+ if (!repositoryManager.isIdle(repository)) {\r
logger.debug(MessageFormat.format("GCExecutor is skipping {0} because it is not idle", repositoryName));\r
continue;\r
}\r
\r
running.set(false);\r
}\r
-\r
- private boolean isRepositoryIdle(Repository repository) {\r
- try {\r
- // Read the use count.\r
- // An idle use count is 2:\r
- // +1 for being in the cache\r
- // +1 for the repository parameter in this method\r
- Field useCnt = Repository.class.getDeclaredField("useCnt");\r
- useCnt.setAccessible(true);\r
- int useCount = ((AtomicInteger) useCnt.get(repository)).get();\r
- return useCount == 2;\r
- } catch (Exception e) {\r
- logger.warn(MessageFormat\r
- .format("Failed to reflectively determine use count for repository {0}",\r
- repository.getDirectory().getPath()), e);\r
- }\r
- return false;\r
- }\r
}\r