org.elasticsearch.common.inject.multibindings.Multibinder Java Examples

The following examples show how to use org.elasticsearch.common.inject.multibindings.Multibinder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptModule.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    MapBinder<String, NativeScriptFactory> scriptsBinder
            = MapBinder.newMapBinder(binder(), String.class, NativeScriptFactory.class);
    for (Map.Entry<String, Class<? extends NativeScriptFactory>> entry : scripts.entrySet()) {
        scriptsBinder.addBinding(entry.getKey()).to(entry.getValue()).asEagerSingleton();
    }

    Multibinder<ScriptEngineService> multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class);
    multibinder.addBinding().to(NativeScriptEngineService.class);
    
    try {
        Class.forName("com.github.mustachejava.Mustache");
        multibinder.addBinding().to(MustacheScriptEngineService.class).asEagerSingleton();
    } catch (Throwable t) {
        Loggers.getLogger(ScriptService.class, settings).debug("failed to load mustache", t);
    }

    for (Class<? extends ScriptEngineService> scriptEngine : scriptEngines) {
        multibinder.addBinding().to(scriptEngine).asEagerSingleton();
    }

    bind(ScriptContextRegistry.class).toInstance(new ScriptContextRegistry(customScriptContexts));
    bind(ScriptService.class).asEagerSingleton();
}
 
Example #2
Source File: IndexShardModule.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    bind(ShardId.class).toInstance(shardId);
    if (IndexMetaData.isIndexUsingDLEngine(settings)) {
        bind(IndexShard.class).to(DLBasedIndexShard.class).asEagerSingleton();
        bind(TranslogService.class).asEagerSingleton();
    }else if (useShadowEngine()) {
        bind(IndexShard.class).to(ShadowIndexShard.class).asEagerSingleton();
    } else {
        bind(IndexShard.class).asEagerSingleton();
        bind(TranslogService.class).asEagerSingleton();
    }

    bind(EngineFactory.class).to(engineFactoryImpl);
    bind(StoreRecoveryService.class).asEagerSingleton();
    bind(ShardPercolateService.class).asEagerSingleton();
    bind(ShardTermVectorsService.class).asEagerSingleton();
    bind(IndexSearcherWrappingService.class).asEagerSingleton();
    // this injects an empty set in IndexSearcherWrappingService, otherwise guice can't construct IndexSearcherWrappingService
    Multibinder<IndexSearcherWrapper> multibinder
            = Multibinder.newSetBinder(binder(), IndexSearcherWrapper.class);
}
 
Example #3
Source File: CommandModule.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    Multibinder<Command> multiBinder = Multibinder.newSetBinder(binder(), Command.class);
    multiBinder.addBinding().to(ExitCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HelpCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(PrintCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(SaveCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HistoryCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(VersionCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(LoadCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HttpGetCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HttpHeadCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HttpPostCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HttpPutCommand.class).asEagerSingleton();
    multiBinder.addBinding().to(HttpDeleteCommand.class).asEagerSingleton();

    //Rhino specific commands
    multiBinder.addBinding().to(new TypeLiteral<ToJsonCommand<Object>>() {}).asEagerSingleton();
    multiBinder.addBinding().to(new TypeLiteral<TransportClientCommand<RhinoClientNativeJavaObject>>(){}).asEagerSingleton();
    multiBinder.addBinding().to(new TypeLiteral<NodeClientCommand<RhinoClientNativeJavaObject>>(){}).asEagerSingleton();
    multiBinder.addBinding().to(new TypeLiteral<LocalNodeCommand<RhinoClientNativeJavaObject, NativeObject, Object>>(){}).asEagerSingleton();

    bind(RhinoCommandRegistrar.class).asEagerSingleton();
}
 
Example #4
Source File: SysChecksModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    Multibinder<SysCheck> checksBinder = Multibinder.newSetBinder(binder(), SysCheck.class);
    checksBinder.addBinding().to(MinMasterNodesSysCheck.class);
    checksBinder.addBinding().to(RecoveryExpectedNodesSysCheck.class);
    checksBinder.addBinding().to(RecoveryAfterTimeSysCheck.class);
    checksBinder.addBinding().to(RecoveryAfterNodesSysCheck.class);
    checksBinder.addBinding().to(NumberOfPartitionsSysCheck.class);
    checksBinder.addBinding().to(JvmVersionSysCheck.class);
}
 
Example #5
Source File: DiscoveryModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    String defaultType = DiscoveryNode.localNode(settings) ? "local" : "zen";
    String discoveryType = settings.get(DISCOVERY_TYPE_KEY, defaultType);
    Class<? extends Discovery> discoveryClass = discoveryTypes.get(discoveryType);
    if (discoveryClass == null) {
        throw new IllegalArgumentException("Unknown Discovery type [" + discoveryType + "]");
    }

    if (discoveryType.equals("zen")) {
        String masterServiceTypeKey = settings.get(ZEN_MASTER_SERVICE_TYPE_KEY, "zen");
        final Class<? extends ElectMasterService> masterService = masterServiceType.get(masterServiceTypeKey);
        if (masterService == null) {
            throw new IllegalArgumentException("Unknown master service type [" + masterServiceTypeKey + "]");
        }
        if (masterService == ElectMasterService.class) {
            bind(ElectMasterService.class).asEagerSingleton();
        } else {
            bind(ElectMasterService.class).to(masterService).asEagerSingleton();
        }
        bind(ZenPingService.class).asEagerSingleton();
        Multibinder<UnicastHostsProvider> unicastHostsProviderMultibinder = Multibinder.newSetBinder(binder(), UnicastHostsProvider.class);
        for (Class<? extends UnicastHostsProvider> unicastHostProvider : unicastHostProviders) {
            unicastHostsProviderMultibinder.addBinding().to(unicastHostProvider);
        }
        zenPings.bind(binder());
    }
    bind(Discovery.class).to(discoveryClass).asEagerSingleton();
    bind(DiscoveryService.class).asEagerSingleton();
}
 
Example #6
Source File: SearchModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void configureFetchSubPhase() {
    Multibinder<FetchSubPhase> fetchSubPhaseMultibinder = Multibinder.newSetBinder(binder(), FetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(ExplainFetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(FieldDataFieldsFetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(ScriptFieldsFetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(FetchSourceSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(VersionFetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(MatchedQueriesFetchSubPhase.class);
    fetchSubPhaseMultibinder.addBinding().to(HighlightPhase.class);
    for (Class<? extends FetchSubPhase> clazz : fetchSubPhases) {
        fetchSubPhaseMultibinder.addBinding().to(clazz);
    }
    bind(InnerHitsFetchSubPhase.class).asEagerSingleton();
}
 
Example #7
Source File: SearchModule.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected void configureFunctionScore() {
    Multibinder<ScoreFunctionParser> parserMapBinder = Multibinder.newSetBinder(binder(), ScoreFunctionParser.class);
    for (Class<? extends ScoreFunctionParser> clazz : functionScoreParsers) {
        parserMapBinder.addBinding().to(clazz);
    }
    bind(ScoreFunctionParserMapper.class);
}
 
Example #8
Source File: ExtensionPoint.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected final void bindExtensions(Binder binder) {
    Multibinder<T> allocationMultibinder = Multibinder.newSetBinder(binder, extensionClass);
    for (Class<? extends T> clazz : extensions) {
        binder.bind(clazz).asEagerSingleton();
        allocationMultibinder.addBinding().to(clazz);
    }
}
 
Example #9
Source File: LicenseModule.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    Multibinder<SysCheck> checksBinder = Multibinder.newSetBinder(binder(), SysCheck.class);
    checksBinder.addBinding().to(LicenseCheck.class);

    bind(LicenseService.class).to(EnterpriseLicenseService.class).asEagerSingleton();
    bind(TransportSetLicenseAction.class).asEagerSingleton();
}
 
Example #10
Source File: SessionSettingModule.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    bind(SessionSettingRegistry.class).asEagerSingleton();
    var sessionSettingProviderBinder = Multibinder.newSetBinder(binder(), SessionSettingProvider.class);
    sessionSettingProviderBinder.addBinding().to(LoadedRules.class);
}
 
Example #11
Source File: SysChecksModule.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure() {
    Multibinder<SysCheck> checksBinder = Multibinder.newSetBinder(binder(), SysCheck.class);
    checksBinder.addBinding().to(NumberOfPartitionsSysCheck.class);
    checksBinder.addBinding().to(TablesNeedUpgradeSysCheck.class);
}