allow to access the global node settings in a static manner
This commit is contained in:
parent
e365ecce10
commit
435eabd4a0
|
@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterStateListener;
|
|||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -36,6 +37,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
*/
|
||||
public class NodeSettingsService extends AbstractComponent implements ClusterStateListener {
|
||||
|
||||
private static volatile Settings globalSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||
|
||||
/**
|
||||
* Returns the global (static) settings last updated by a node. Note, if you have multiple
|
||||
* nodes on the same JVM, it will just return the latest one set...
|
||||
*/
|
||||
public static Settings getGlobalSettings() {
|
||||
return globalSettings;
|
||||
}
|
||||
|
||||
private volatile Settings lastSettingsApplied;
|
||||
|
||||
private final CopyOnWriteArrayList<Listener> listeners = new CopyOnWriteArrayList<Listener>();
|
||||
|
@ -43,6 +54,7 @@ public class NodeSettingsService extends AbstractComponent implements ClusterSta
|
|||
@Inject
|
||||
public NodeSettingsService(Settings settings) {
|
||||
super(settings);
|
||||
globalSettings = settings;
|
||||
}
|
||||
|
||||
// inject it as a member, so we won't get into possible cyclic problems
|
||||
|
@ -91,6 +103,7 @@ public class NodeSettingsService extends AbstractComponent implements ClusterSta
|
|||
}
|
||||
|
||||
lastSettingsApplied = event.state().metaData().settings();
|
||||
globalSettings = lastSettingsApplied;
|
||||
}
|
||||
|
||||
public void addListener(Listener listener) {
|
||||
|
|
Loading…
Reference in New Issue