Search in sources :

Example 1 with BatchProgramModule

use of com.google.gerrit.pgm.util.BatchProgramModule in project gerrit by GerritCodeReview.

the class Reindex method createSysInjector.

private Injector createSysInjector() {
    Map<String, Integer> versions = new HashMap<>();
    if (changesVersion != null) {
        versions.put(ChangeSchemaDefinitions.INSTANCE.getName(), changesVersion);
    }
    boolean replica = ReplicaUtil.isReplica(globalConfig);
    List<Module> modules = new ArrayList<>();
    Module indexModule;
    IndexType indexType = IndexModule.getIndexType(dbInjector);
    if (indexType.isLucene()) {
        indexModule = LuceneIndexModule.singleVersionWithExplicitVersions(versions, threads, replica, AutoFlush.DISABLED);
    } else if (indexType.isFake()) {
        // compile the component in.
        try {
            Class<?> clazz = Class.forName("com.google.gerrit.index.testing.FakeIndexModule");
            Method m = clazz.getMethod("singleVersionWithExplicitVersions", Map.class, int.class, boolean.class);
            indexModule = (Module) m.invoke(null, versions, threads, replica);
        } catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException | InvocationTargetException e) {
            throw new IllegalStateException("can't create index", e);
        }
    } else {
        throw new IllegalStateException("unsupported index.type = " + indexType);
    }
    modules.add(indexModule);
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            super.configure();
            OptionalBinder.newOptionalBinder(binder(), IsFirstInsertForEntry.class).setBinding().toInstance(IsFirstInsertForEntry.YES);
        }
    });
    modules.add(new BatchProgramModule(dbInjector));
    modules.add(new FactoryModule() {

        @Override
        protected void configure() {
            factory(ChangeResource.Factory.class);
        }
    });
    return dbInjector.createChildInjector(ModuleOverloader.override(modules, LibModuleLoader.loadReindexModules(cfgInjector, versions, threads, replica)));
}
Also used : HashMap(java.util.HashMap) IsFirstInsertForEntry(com.google.gerrit.server.index.options.IsFirstInsertForEntry) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) BatchProgramModule(com.google.gerrit.pgm.util.BatchProgramModule) Module(com.google.inject.Module) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) IndexModule(com.google.gerrit.server.index.IndexModule) BatchProgramModule(com.google.gerrit.pgm.util.BatchProgramModule) AbstractModule(com.google.inject.AbstractModule) IndexType(com.google.gerrit.index.IndexType) Map(java.util.Map) HashMap(java.util.HashMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Aggregations

FactoryModule (com.google.gerrit.extensions.config.FactoryModule)1 DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)1 IndexType (com.google.gerrit.index.IndexType)1 LuceneIndexModule (com.google.gerrit.lucene.LuceneIndexModule)1 BatchProgramModule (com.google.gerrit.pgm.util.BatchProgramModule)1 IndexModule (com.google.gerrit.server.index.IndexModule)1 IsFirstInsertForEntry (com.google.gerrit.server.index.options.IsFirstInsertForEntry)1 AbstractModule (com.google.inject.AbstractModule)1 Module (com.google.inject.Module)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1