Java Code Examples for org.elasticsearch.common.inject.Injector#getInstance()
The following examples show how to use
org.elasticsearch.common.inject.Injector#getInstance() .
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: IkESPluginTest.java From es-ik with Apache License 2.0 | 6 votes |
@Test public void testDefaultsIcuAnalysis() { Index index = new Index("test"); Settings settings = ImmutableSettings.settingsBuilder() .put("path.home", "none") .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), new IndexNameModule(index), new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor())) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer"); MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class)); }
Example 2
Source File: HanLpAnalysisTests.java From elasticsearch-analysis-hanlp with Apache License 2.0 | 6 votes |
@Test public void testDefaultsIcuAnalysis() { Index index = new Index("test"); Settings settings = settingsBuilder() .put("path.home", createTempDir()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector(); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, settings), new IndexNameModule(index), new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new HanLpAnalysisBinderProcessor())) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); TokenizerFactory tokenizerFactory = analysisService.tokenizer("smartcn_tokenizer"); MatcherAssert.assertThat(tokenizerFactory, instanceOf(HanLpTokenizerTokenizerFactory.class)); }
Example 3
Source File: BlobIndices.java From Elasticsearch with Apache License 2.0 | 5 votes |
public BlobShard blobShard(String index, int shardId) { IndexService indexService = indicesService.indexService(index); if (indexService != null) { try { Injector injector = indexService.shardInjectorSafe(shardId); return injector.getInstance(BlobShard.class); } catch (ShardNotFoundException e) { return null; } } return null; }
Example 4
Source File: IndicesService.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Inject public IndicesService(Settings settings, IndicesLifecycle indicesLifecycle, IndicesAnalysisService indicesAnalysisService, Injector injector, NodeEnvironment nodeEnv) { super(settings); this.indicesLifecycle = (InternalIndicesLifecycle) indicesLifecycle; this.indicesAnalysisService = indicesAnalysisService; this.injector = injector; this.pluginsService = injector.getInstance(PluginsService.class); this.indicesLifecycle.addListener(oldShardsStats); this.nodeEnv = nodeEnv; this.shardsClosedTimeout = settings.getAsTime(INDICES_SHARDS_CLOSED_TIMEOUT, new TimeValue(1, TimeUnit.DAYS)); }
Example 5
Source File: MapperTestUtils.java From Elasticsearch with Apache License 2.0 | 5 votes |
private static AnalysisService newAnalysisService(Settings indexSettings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector(); Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); }
Example 6
Source File: TransportClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
private TransportClient(Injector injector) { super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class), injector.getInstance(Headers.class)); this.injector = injector; this.clusterName = injector.getInstance(ClusterName.class); this.transportService = injector.getInstance(TransportService.class); this.minCompatibilityVersion = injector.getInstance(Version.class).minimumCompatibilityVersion(); this.headers = injector.getInstance(Headers.class); this.pingTimeout = this.settings.getAsTime("client.transport.ping_timeout", timeValueSeconds(5)).millis(); this.proxyActionMap = injector.getInstance(ProxyActionMap.class); }
Example 7
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static AnalysisService newAnalysisService(Settings indexSettings) { Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector(); Index index = new Index("test"); Injector injector = new ModulesBuilder().add( new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector); return injector.getInstance(AnalysisService.class); }
Example 8
Source File: MapperTestUtils.java From elasticsearch-analysis-baseform with Apache License 2.0 | 5 votes |
public static MapperService newMapperService(Settings settings, Client client) { Settings indexSettings = Settings.builder() .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put("path.home", System.getProperty("path.home")) .put("client.type", "node") .put(settings) .build(); Index index = new Index("test"); Injector parentInjector = new ModulesBuilder() .add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))) .createInjector(); AnalysisModule analysisModule = new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class)); new AnalysisBaseformPlugin(settings).onModule(analysisModule); Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings), new IndexNameModule(index), analysisModule) .createChildInjector(parentInjector); AnalysisService analysisService = injector.getInstance(AnalysisService.class); SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings); Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers(); Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers(); MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers); return new MapperService(new Index("test"), indexSettings, analysisService, similarityLookupService, null, mapperRegistry); }
Example 9
Source File: JLineRhinoCompleterTest.java From elasticshell with Apache License 2.0 | 5 votes |
@BeforeClass public void init() { Injector injector = Guice.createInjector(new ShellModule(), new JLineModule(), new RhinoShellModule()); Context context = Context.enter(); context.setWrapFactory(new RhinoCustomWrapFactory()); completer = injector.getInstance(JLineRhinoCompleter.class); }
Example 10
Source File: TransportClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
/** * Builds a new instance of the transport client. */ public TransportClient build() { Settings settings = InternalSettingsPreparer.prepareSettings(this.settings); settings = settingsBuilder() .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval .put(settings) .put("network.server", false) .put("node.client", true) .put(CLIENT_TYPE_SETTING, CLIENT_TYPE) .build(); PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; final ThreadPool threadPool = new ThreadPool(settings); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); boolean success = false; try { ModulesBuilder modules = new ModulesBuilder(); modules.add(new Version.Module(version)); // plugin modules must be added here, before others or we can get crazy injection errors... for (Module pluginModule : pluginsService.nodeModules()) { modules.add(pluginModule); } modules.add(new PluginsModule(pluginsService)); modules.add(new SettingsModule(this.settings)); modules.add(new NetworkModule(namedWriteableRegistry)); modules.add(new ClusterNameModule(this.settings)); modules.add(new ThreadPoolModule(threadPool)); modules.add(new TransportModule(this.settings, namedWriteableRegistry)); modules.add(new SearchModule() { @Override protected void configure() { // noop } }); modules.add(new ActionModule(true)); modules.add(new ClientTransportModule()); modules.add(new CircuitBreakerModule(this.settings)); pluginsService.processModules(modules); Injector injector = modules.createInjector(); final TransportService transportService = injector.getInstance(TransportService.class); transportService.start(); transportService.acceptIncomingRequests(); TransportClient transportClient = new TransportClient(injector); success = true; return transportClient; } finally { if (!success) { ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); } } }
Example 11
Source File: TransportClient.java From Elasticsearch with Apache License 2.0 | 4 votes |
private TransportClient(Injector injector) { super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class), injector.getInstance(Headers.class)); this.injector = injector; nodesService = injector.getInstance(TransportClientNodesService.class); proxy = injector.getInstance(TransportProxyClient.class); }
Example 12
Source File: Main.java From elasticshell with Apache License 2.0 | 4 votes |
public static void main(String... args) { Injector injector = Guice.createInjector(new ShellModule(), new JLineModule(), new RhinoShellModule(), new CommandModule()); Shell shell = injector.getInstance(Shell.class); shell.run(); }
Example 13
Source File: Parameter.java From crate with Apache License 2.0 | 4 votes |
/** * Returns the Guice {@link Key} for this parameter. */ public Object getValue(Injector injector) { return isProvider ? injector.getProvider(getBindingForType(getProvidedType(type))) : injector.getInstance(getPrimaryBindingKey()); }