Skip to content

Commit 435eabd

Browse files
kimchyimotov
authored andcommitted
allow to access the global node settings in a static manner
1 parent e365ecc commit 435eabd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/org/elasticsearch/node/settings/NodeSettingsService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.common.component.AbstractComponent;
2626
import org.elasticsearch.common.inject.Inject;
2727
import org.elasticsearch.common.logging.ESLoggerFactory;
28+
import org.elasticsearch.common.settings.ImmutableSettings;
2829
import org.elasticsearch.common.settings.Settings;
2930

3031
import java.util.Map;
@@ -36,13 +37,24 @@
3637
*/
3738
public class NodeSettingsService extends AbstractComponent implements ClusterStateListener {
3839

40+
private static volatile Settings globalSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
41+
42+
/**
43+
* Returns the global (static) settings last updated by a node. Note, if you have multiple
44+
* nodes on the same JVM, it will just return the latest one set...
45+
*/
46+
public static Settings getGlobalSettings() {
47+
return globalSettings;
48+
}
49+
3950
private volatile Settings lastSettingsApplied;
4051

4152
private final CopyOnWriteArrayList<Listener> listeners = new CopyOnWriteArrayList<Listener>();
4253

4354
@Inject
4455
public NodeSettingsService(Settings settings) {
4556
super(settings);
57+
globalSettings = settings;
4658
}
4759

4860
// inject it as a member, so we won't get into possible cyclic problems
@@ -91,6 +103,7 @@ public void clusterChanged(ClusterChangedEvent event) {
91103
}
92104

93105
lastSettingsApplied = event.state().metaData().settings();
106+
globalSettings = lastSettingsApplied;
94107
}
95108

96109
public void addListener(Listener listener) {

0 commit comments

Comments
 (0)