Allow passing an executor directly into IndexModule
Change-Id: I3e156cee30b231e54608ecbf08c4e64a0e4d9661
This commit is contained in:
@@ -21,6 +21,7 @@ import com.google.gerrit.server.config.GerritServerConfig;
|
|||||||
import com.google.gerrit.server.git.WorkQueue;
|
import com.google.gerrit.server.git.WorkQueue;
|
||||||
import com.google.gerrit.server.git.WorkQueue.Executor;
|
import com.google.gerrit.server.git.WorkQueue.Executor;
|
||||||
import com.google.gerrit.server.query.change.ChangeQueryRewriter;
|
import com.google.gerrit.server.query.change.ChangeQueryRewriter;
|
||||||
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
@@ -48,9 +49,16 @@ public class IndexModule extends LifecycleModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final int threads;
|
private final int threads;
|
||||||
|
private final ListeningScheduledExecutorService indexExecutor;
|
||||||
|
|
||||||
public IndexModule(int threads) {
|
public IndexModule(int threads) {
|
||||||
this.threads = threads;
|
this.threads = threads;
|
||||||
|
this.indexExecutor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IndexModule(ListeningScheduledExecutorService indexExecutor) {
|
||||||
|
this.threads = -1;
|
||||||
|
this.indexExecutor = indexExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,25 +70,14 @@ public class IndexModule extends LifecycleModule {
|
|||||||
install(new FactoryModuleBuilder()
|
install(new FactoryModuleBuilder()
|
||||||
.implement(ChangeIndexer.class, ChangeIndexerImpl.class)
|
.implement(ChangeIndexer.class, ChangeIndexerImpl.class)
|
||||||
.build(ChangeIndexer.Factory.class));
|
.build(ChangeIndexer.Factory.class));
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
if (indexExecutor != null) {
|
||||||
@Singleton
|
bind(ListeningScheduledExecutorService.class)
|
||||||
@IndexExecutor
|
.annotatedWith(IndexExecutor.class)
|
||||||
ListeningScheduledExecutorService getIndexExecutor(
|
.toInstance(indexExecutor);
|
||||||
@GerritServerConfig Config config,
|
|
||||||
WorkQueue workQueue) {
|
|
||||||
int threads = this.threads;
|
|
||||||
if (threads <= 0) {
|
|
||||||
threads = config.getInt("index", null, "threads", 0);
|
|
||||||
}
|
|
||||||
Executor executor;
|
|
||||||
if (threads <= 0) {
|
|
||||||
executor = workQueue.getDefaultQueue();
|
|
||||||
} else {
|
} else {
|
||||||
executor = workQueue.createQueue(threads, "index");
|
install(new IndexExecutorModule(threads));
|
||||||
}
|
}
|
||||||
return MoreExecutors.listeningDecorator(executor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@@ -89,4 +86,35 @@ public class IndexModule extends LifecycleModule {
|
|||||||
IndexCollection indexes) {
|
IndexCollection indexes) {
|
||||||
return factory.create(indexes);
|
return factory.create(indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class IndexExecutorModule extends AbstractModule {
|
||||||
|
private final int threads;
|
||||||
|
|
||||||
|
private IndexExecutorModule(int threads) {
|
||||||
|
this.threads = threads;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
@IndexExecutor
|
||||||
|
ListeningScheduledExecutorService getIndexExecutor(
|
||||||
|
@GerritServerConfig Config config,
|
||||||
|
WorkQueue workQueue) {
|
||||||
|
int threads = this.threads;
|
||||||
|
if (threads <= 0) {
|
||||||
|
threads = config.getInt("index", null, "threads", 0);
|
||||||
|
}
|
||||||
|
Executor executor;
|
||||||
|
if (threads <= 0) {
|
||||||
|
executor = workQueue.getDefaultQueue();
|
||||||
|
} else {
|
||||||
|
executor = workQueue.createQueue(threads, "index");
|
||||||
|
}
|
||||||
|
return MoreExecutors.listeningDecorator(executor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user