allow to access the global node settings in a static manner

This commit is contained in:
Shay Banon 2013-02-17 00:38:01 +01:00 committed by Igor Motov
parent e365ecce10
commit 435eabd4a0
1 changed files with 13 additions and 0 deletions

View File

@ -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) {