Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.x] Changed the sequence of Guice injection #456

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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