Skip to content

Commit

Permalink
Changed the sequence of Guice injection (opensearch-project#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
owaiskazi19 authored Feb 15, 2023
1 parent 514f796 commit 276a965
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main/java/org/opensearch/sdk/ExtensionsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ protected ExtensionsRunner(Extension extension) throws IOException {
.put(TransportSettings.PORT.getKey(), extensionSettings.getHostPort())
.build();
this.threadPool = new ThreadPool(settings);

Guice.createInjector(b -> {
b.bind(ExtensionsRunner.class).toInstance(this);
b.bind(Extension.class).toInstance(extension);

b.bind(NamedXContentRegistry.class).toInstance(getNamedXContentRegistry().getRegistry());
b.bind(ThreadPool.class).toInstance(getThreadPool());

b.bind(SDKClient.class).toInstance(new SDKClient());
b.bind(SDKClusterService.class).toInstance(new SDKClusterService(this));

// create components
injectComponents(b);
});

if (extension instanceof ActionExtension) {
// store REST handlers in the registry
for (ExtensionRestHandler extensionRestHandler : ((ActionExtension) extension).getExtensionRestHandlers()) {
Expand All @@ -164,19 +179,6 @@ protected ExtensionsRunner(Extension extension) throws IOException {
// save custom transport actions
this.transportActions = new TransportActions(extension.getActionsMap());

Guice.createInjector(b -> {
b.bind(ExtensionsRunner.class).toInstance(this);
b.bind(Extension.class).toInstance(extension);

b.bind(NamedXContentRegistry.class).toInstance(getNamedXContentRegistry().getRegistry());
b.bind(ThreadPool.class).toInstance(getThreadPool());

b.bind(SDKClient.class).toInstance(new SDKClient());
b.bind(SDKClusterService.class).toInstance(new SDKClusterService(this));

// create components
injectComponents(b);
});
// TODO: put getactions in a MapBinder
// Requires https://github.com/opensearch-project/opensearch-sdk-java/pull/434
}
Expand Down

0 comments on commit 276a965

Please sign in to comment.