aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2017-06-11 01:20:34 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2017-06-11 12:24:12 +0200
commit18ae9bb57db46d7d8720394cf409d56cd4b750f7 (patch)
tree97e5365e7036049b2a9ff8fcf582521525fbd683 /org.eclipse.jgit/src/org/eclipse
parentb6f954ad426f91561b4aa09d7ba23652516e7b0a (diff)
downloadjgit-18ae9bb57db46d7d8720394cf409d56cd4b750f7.tar.gz
jgit-18ae9bb57db46d7d8720394cf409d56cd4b750f7.zip
Allow to use an external ExecutorService for background auto-gc
If set use the external executor, otherwise use JGit's own simple WorkQueue. Move WorkQueue to an internal package so we can reuse it without exposing it in the public API. Change-Id: I060d62ffd6692362a88b4bf13ee07b0dc857abe9 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java)9
4 files changed, 28 insertions, 6 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 17f3e6ab84..ad611d3505 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -78,7 +78,6 @@ import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -107,6 +106,7 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Ref.Storage;
+import org.eclipse.jgit.lib.internal.WorkQueue;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.ReflogReader;
@@ -151,7 +151,19 @@ public class GC {
private static final int DEFAULT_AUTOLIMIT = 6700;
- private static ExecutorService executor = Executors.newFixedThreadPool(1);
+ private static volatile ExecutorService executor;
+
+ /**
+ * Set the executor for running auto-gc in the background. If no executor is
+ * set JGit's own WorkQueue will be used.
+ *
+ * @param e
+ * the executor to be used for running auto-gc
+ * @since 4.8
+ */
+ public static void setExecutor(ExecutorService e) {
+ executor = e;
+ }
private final FileRepository repo;
@@ -271,7 +283,7 @@ public class GC {
}
return Collections.emptyList();
};
- Future<Collection<PackFile>> result = executor.submit(gcTask);
+ Future<Collection<PackFile>> result = executor().submit(gcTask);
if (background) {
// TODO(ms): in 5.0 change signature and return the Future
return Collections.emptyList();
@@ -283,6 +295,10 @@ public class GC {
}
}
+ private ExecutorService executor() {
+ return (executor != null) ? executor : WorkQueue.getExecutor();
+ }
+
private Collection<PackFile> doGc() throws IOException, ParseException {
if (automatic && !needGc()) {
return Collections.emptyList();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
index 54c80522b8..a75293d6cb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
@@ -46,6 +46,8 @@ package org.eclipse.jgit.lib;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jgit.lib.internal.WorkQueue;
+
/** ProgressMonitor that batches update events. */
public abstract class BatchingProgressMonitor implements ProgressMonitor {
private long delayStartTime;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
index baa5286862..53e9fe3c53 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
@@ -55,6 +55,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.lib.internal.WorkQueue;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java
index 07b87f58d2..3303f47722 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java
@@ -41,7 +41,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package org.eclipse.jgit.lib;
+package org.eclipse.jgit.lib.internal;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -50,7 +50,7 @@ import java.util.concurrent.ThreadFactory;
/**
* Simple work queue to run tasks in the background
*/
-class WorkQueue {
+public class WorkQueue {
private static final ScheduledThreadPoolExecutor executor;
static final Object executorKiller;
@@ -94,7 +94,10 @@ class WorkQueue {
};
}
- static ScheduledThreadPoolExecutor getExecutor() {
+ /**
+ * @return the WorkQueue's executor
+ */
+ public static ScheduledThreadPoolExecutor getExecutor() {
return executor;
}
}