Browse Source

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>
stable-4.8
Matthias Sohn 8 years ago
parent
commit
18ae9bb57d
  1. 1
      org.eclipse.jgit/META-INF/MANIFEST.MF
  2. 22
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchingProgressMonitor.java
  4. 1
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
  5. 9
      org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/WorkQueue.java

1
org.eclipse.jgit/META-INF/MANIFEST.MF

@ -85,6 +85,7 @@ Export-Package: org.eclipse.jgit.annotations;version="4.8.0",
org.eclipse.jgit.treewalk,
org.eclipse.jgit.transport,
org.eclipse.jgit.submodule",
org.eclipse.jgit.lib.internal;version="4.8.0";x-internal:=true,
org.eclipse.jgit.merge;version="4.8.0";
uses:="org.eclipse.jgit.lib,
org.eclipse.jgit.treewalk,

22
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();

2
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;

1
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;

9
org.eclipse.jgit/src/org/eclipse/jgit/lib/WorkQueue.java → 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;
}
}
Loading…
Cancel
Save