diff --git a/server/src/main/java/org/elasticsearch/inference/InferenceServiceRegistry.java b/server/src/main/java/org/elasticsearch/inference/InferenceServiceRegistry.java index a0ed7bbd82b24..d5973807d9d78 100644 --- a/server/src/main/java/org/elasticsearch/inference/InferenceServiceRegistry.java +++ b/server/src/main/java/org/elasticsearch/inference/InferenceServiceRegistry.java @@ -9,9 +9,9 @@ package org.elasticsearch.inference; import org.elasticsearch.client.internal.Client; -import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; +import java.io.Closeable; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -20,7 +20,7 @@ import java.util.function.Function; import java.util.stream.Collectors; -public class InferenceServiceRegistry extends AbstractLifecycleComponent { +public class InferenceServiceRegistry implements Closeable { private final Map services; private final List namedWriteables = new ArrayList<>(); @@ -53,17 +53,9 @@ public List getNamedWriteables() { } @Override - protected void doStart() { - - } - - @Override - protected void doStop() { - - } - - @Override - protected void doClose() throws IOException { - + public void close() throws IOException { + for (var service : services.values()) { + service.close(); + } } } diff --git a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java index e25b223742edd..ea62ca8620bf5 100644 --- a/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java +++ b/x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/InferencePlugin.java @@ -72,8 +72,6 @@ public class InferencePlugin extends Plugin implements ActionPlugin, ExtensibleP public static final String NAME = "inference"; public static final String UTILITY_THREAD_POOL_NAME = "inference_utility"; private final Settings settings; - // We'll keep a reference to the http manager just in case the inference services don't get closed individually - private final SetOnce httpManager = new SetOnce<>(); private final SetOnce httpFactory = new SetOnce<>(); private final SetOnce serviceComponents = new SetOnce<>(); @@ -120,11 +118,9 @@ public Collection createComponents(PluginServices services) { var truncator = new Truncator(settings, services.clusterService()); serviceComponents.set(new ServiceComponents(services.threadPool(), throttlerManager, settings, truncator)); - httpManager.set(HttpClientManager.create(settings, services.threadPool(), services.clusterService(), throttlerManager)); - var httpRequestSenderFactory = new HttpRequestSenderFactory( services.threadPool(), - httpManager.get(), + HttpClientManager.create(settings, services.threadPool(), services.clusterService(), throttlerManager), services.clusterService(), settings ); @@ -236,6 +232,6 @@ public void close() { var serviceComponentsRef = serviceComponents.get(); var throttlerToClose = serviceComponentsRef != null ? serviceComponentsRef.throttlerManager() : null; - IOUtils.closeWhileHandlingException(httpManager.get(), throttlerToClose); + IOUtils.closeWhileHandlingException(inferenceServiceRegistry.get(), throttlerToClose); } }