
org.elasticsearch.common.inject.ModulesBuilder Maven / Gradle / Ivy
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.common.inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class ModulesBuilder implements Iterable {
private final List modules = new ArrayList<>();
public ModulesBuilder add(Module... newModules) {
Collections.addAll(modules, newModules);
return this;
}
@Override
public Iterator iterator() {
return modules.iterator();
}
public Injector createInjector() {
Injector injector = Guice.createInjector(modules);
((InjectorImpl) injector).clearCache();
// in ES, we always create all instances as if they are eager singletons
// this allows for considerable memory savings (no need to store construction info) as well as cycles
((InjectorImpl) injector).readOnlyAllSingletons();
return injector;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy