Skip to content

Commit 89a8524

Browse files
committed
use method instead of supplier
1 parent 639d702 commit 89a8524

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/InferenceEndpointRegistry.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.Collection;
2828
import java.util.List;
29-
import java.util.function.Supplier;
3029

3130
/**
3231
* A registry that assembles and caches Inference Endpoints, {@link Model}, for reuse.
@@ -67,7 +66,8 @@ public static Collection<? extends Setting<?>> getSettingsDefinitions() {
6766
private final InferenceServiceRegistry serviceRegistry;
6867
private final ProjectResolver projectResolver;
6968
private final Cache<InferenceIdAndProject, Model> cache;
70-
private final Supplier<Boolean> cacheEnabledViaFeature;
69+
private final ClusterService clusterService;
70+
private final FeatureService featureService;
7171
private volatile boolean cacheEnabledViaSetting;
7272

7373
public InferenceEndpointRegistry(
@@ -85,10 +85,8 @@ public InferenceEndpointRegistry(
8585
.setMaximumWeight(INFERENCE_ENDPOINT_CACHE_WEIGHT.get(settings))
8686
.setExpireAfterWrite(INFERENCE_ENDPOINT_CACHE_EXPIRY.get(settings))
8787
.build();
88-
this.cacheEnabledViaFeature = () -> {
89-
var state = clusterService.state();
90-
return state.clusterRecovered() && featureService.clusterHasFeature(state, InferenceFeatures.INFERENCE_ENDPOINT_CACHE);
91-
};
88+
this.clusterService = clusterService;
89+
this.featureService = featureService;
9290
this.cacheEnabledViaSetting = INFERENCE_ENDPOINT_CACHE_ENABLED.get(settings);
9391

9492
clusterService.getClusterSettings()
@@ -151,7 +149,12 @@ public int cacheCount() {
151149
}
152150

153151
public boolean cacheEnabled() {
154-
return cacheEnabledViaSetting && cacheEnabledViaFeature.get();
152+
return cacheEnabledViaSetting && cacheEnabledViaFeature();
153+
}
154+
155+
private boolean cacheEnabledViaFeature() {
156+
var state = clusterService.state();
157+
return state.clusterRecovered() && featureService.clusterHasFeature(state, InferenceFeatures.INFERENCE_ENDPOINT_CACHE);
155158
}
156159

157160
private record InferenceIdAndProject(String inferenceEntityId, ProjectId projectId) {}

0 commit comments

Comments
 (0)