forked from opensearch-project/neural-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuralSearchSettingsAccessor.java
44 lines (36 loc) · 1.41 KB
/
NeuralSearchSettingsAccessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
package org.opensearch.neuralsearch.settings;
import lombok.Getter;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.settings.Settings;
import org.opensearch.neuralsearch.stats.events.EventStatsManager;
public class NeuralSearchSettingsAccessor {
private static NeuralSearchSettingsAccessor INSTANCE;
private boolean initialized;
@Getter
private volatile Boolean isStatsEnabled;
/**
* Return instance of the cluster context, must be initialized first for proper usage
* @return instance of cluster context
*/
public static synchronized NeuralSearchSettingsAccessor instance() {
if (INSTANCE == null) {
INSTANCE = new NeuralSearchSettingsAccessor();
}
return INSTANCE;
}
public void initialize(ClusterService clusterService, Settings settings) {
if (initialized) return;
isStatsEnabled = NeuralSearchSettings.NEURAL_STATS_ENABLED.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(NeuralSearchSettings.NEURAL_STATS_ENABLED, value -> {
// If stats are being toggled off, clear and reset all stats
if (isStatsEnabled && (value == false)) {
EventStatsManager.instance().reset();
}
isStatsEnabled = value;
});
}
}