Class AbstractScopedSettings
java.lang.Object
org.elasticsearch.common.settings.AbstractScopedSettings
- Direct Known Subclasses:
ClusterSettings
,IndexScopedSettings
A basic setting service that can be used for per-index and per-cluster settings.
This service offers transactional application of updates settings.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Transactional interface to update settings. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractScopedSettings(Settings settings, Set<Setting<?>> settingsSet, Set<SettingUpgrader<?>> settingUpgraders, Setting.Property scope)
protected
AbstractScopedSettings(Settings nodeSettings, Settings scopeSettings, AbstractScopedSettings other, org.apache.logging.log4j.Logger logger)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAffixGroupUpdateConsumer(List<Setting.AffixSetting<?>> settings, BiConsumer<String,Settings> consumer)
Adds a affix settings consumer that accepts the settings for a group of settings.<T> void
addAffixMapUpdateConsumer(Setting.AffixSetting<T> setting, Consumer<Map<String,T>> consumer, BiConsumer<String,T> validator)
Adds a settings consumer for affix settings.<A, B> void
addAffixUpdateConsumer(Setting.AffixSetting<A> settingA, Setting.AffixSetting<B> settingB, BiConsumer<String,org.elasticsearch.core.Tuple<A,B>> consumer, BiConsumer<String,org.elasticsearch.core.Tuple<A,B>> validator)
Adds a affix settings consumer that accepts the values for two settings.<T> void
addAffixUpdateConsumer(Setting.AffixSetting<T> setting, BiConsumer<String,T> consumer, BiConsumer<String,T> validator)
Adds a settings consumer for affix settings.void
addSettingsUpdateConsumer(Consumer<Settings> consumer, List<? extends Setting<?>> settings)
Adds a settings consumer that is only executed if any setting in the supplied list of settings is changed.void
addSettingsUpdateConsumer(Consumer<Settings> consumer, List<? extends Setting<?>> settings, Consumer<Settings> validator)
Adds a settings consumer that is only executed if any setting in the supplied list of settings is changed.<A, B> void
addSettingsUpdateConsumer(Setting<A> a, Setting<B> b, BiConsumer<A,B> consumer)
Adds a settings consumer that accepts the values for two settings.<A, B> void
addSettingsUpdateConsumer(Setting<A> a, Setting<B> b, BiConsumer<A,B> consumer, BiConsumer<A,B> validator)
Adds a settings consumer that accepts the values for two settings.<T> void
addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer)
Adds a settings consumer.<T> void
addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer, Consumer<T> validator)
Adds a settings consumer with a predicate that is only evaluated at update time.applySettings(Settings newSettings)
Applies the given settings to all the settings consumers or to none of them.archiveUnknownOrInvalidSettings(Settings settings, Consumer<Map.Entry<String,String>> unknownConsumer, BiConsumer<Map.Entry<String,String>,IllegalArgumentException> invalidConsumer)
Archives invalid or unknown settings.Returns a settings object that contains all settings that are not already set in the given source.Setting<?>
Returns theSetting
for the given key ornull
if the setting can not be found.<T> T
Returns the value for the given setting.getScope()
boolean
isDynamicSetting(String key)
Returnstrue
if the setting for the given key is dynamically updateable.boolean
isFinalSetting(String key)
Returnstrue
if the setting for the given key is final.boolean
isPrivateSetting(String key)
Returnstrue
iff the setting is a private setting ie.static boolean
isValidKey(String key)
Returnstrue
iff the given key is a valid settings key otherwisefalse
boolean
updateDynamicSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type)
Updates a target settings builder with new, updated or deleted settings from a given settings builder.boolean
updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type)
Updates a target settings builder with new, updated or deleted settings from a given settings builder.upgradeSettings(Settings settings)
Upgrade all settings eligible for upgrade in the specified settings instance.void
Validates that all settings are registered and valid.void
Validates that all settings are registered and valid.void
validate(Settings settings, boolean validateValues, boolean ignorePrivateSettings, boolean ignoreArchivedSettings)
Validates that all settings are registered and valid.void
validate(Settings settings, boolean validateValues, boolean ignorePrivateSettings, boolean ignoreArchivedSettings, boolean validateInternalOrPrivateIndex)
Validates that all settings are registered and valid.protected void
validateSettingKey(Setting<?> setting)
validateUpdate(Settings settings)
Validates the given settings by running it through all update listeners without applying it.
-
Field Details
-
ARCHIVED_SETTINGS_PREFIX
- See Also:
- Constant Field Values
-
-
Constructor Details
-
AbstractScopedSettings
protected AbstractScopedSettings(Settings settings, Set<Setting<?>> settingsSet, Set<SettingUpgrader<?>> settingUpgraders, Setting.Property scope) -
AbstractScopedSettings
protected AbstractScopedSettings(Settings nodeSettings, Settings scopeSettings, AbstractScopedSettings other, org.apache.logging.log4j.Logger logger)
-
-
Method Details
-
validateSettingKey
-
isValidKey
Returnstrue
iff the given key is a valid settings key otherwisefalse
-
getScope
-
validateUpdate
Validates the given settings by running it through all update listeners without applying it. This method will not change any settings but will fail if any of the settings can't be applied. -
applySettings
Applies the given settings to all the settings consumers or to none of them. The settings will be merged with the node settings before they are applied while given settings override existing node settings.- Parameters:
newSettings
- the settings to apply- Returns:
- the unmerged applied settings
-
addSettingsUpdateConsumer
public <T> void addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer, Consumer<T> validator)Adds a settings consumer with a predicate that is only evaluated at update time.Note: Only settings registered in
SettingsModule
can be changed dynamically.- Parameters:
validator
- an additional validator that is only applied to updates of this setting. This is useful to add additional validation to settings at runtime compared to at startup time.
-
addSettingsUpdateConsumer
public void addSettingsUpdateConsumer(Consumer<Settings> consumer, List<? extends Setting<?>> settings)Adds a settings consumer that is only executed if any setting in the supplied list of settings is changed. In that case all the settings are specified in the argument are returned. Also automatically adds empty consumers for all settings in order to activate logging -
addSettingsUpdateConsumer
public void addSettingsUpdateConsumer(Consumer<Settings> consumer, List<? extends Setting<?>> settings, Consumer<Settings> validator)Adds a settings consumer that is only executed if any setting in the supplied list of settings is changed. In that case all the settings are specified in the argument are returned. The validator is run across all specified settings before the settings are applied. Also automatically adds empty consumers for all settings in order to activate logging -
addAffixUpdateConsumer
public <T> void addAffixUpdateConsumer(Setting.AffixSetting<T> setting, BiConsumer<String,T> consumer, BiConsumer<String,T> validator)Adds a settings consumer for affix settings. Affix settings have a namespace associated to it that needs to be available to the consumer in order to be processed correctly. -
addAffixUpdateConsumer
public <A, B> void addAffixUpdateConsumer(Setting.AffixSetting<A> settingA, Setting.AffixSetting<B> settingB, BiConsumer<String,org.elasticsearch.core.Tuple<A,B>> consumer, BiConsumer<String,org.elasticsearch.core.Tuple<A,B>> validator)Adds a affix settings consumer that accepts the values for two settings. The consumer is only notified if one or both settings change and if the provided validator succeeded.Note: Only settings registered in
This method registers a compound updater that is useful if two settings are depending on each other. The consumer is always provided with both values even if only one of the two changes.SettingsModule
can be changed dynamically. -
addAffixGroupUpdateConsumer
public void addAffixGroupUpdateConsumer(List<Setting.AffixSetting<?>> settings, BiConsumer<String,Settings> consumer)Adds a affix settings consumer that accepts the settings for a group of settings. The consumer is only notified if at least one of the settings change.Note: Only settings registered in
SettingsModule
can be changed dynamically. -
addAffixMapUpdateConsumer
public <T> void addAffixMapUpdateConsumer(Setting.AffixSetting<T> setting, Consumer<Map<String,T>> consumer, BiConsumer<String,T> validator)Adds a settings consumer for affix settings. Affix settings have a namespace associated to it that needs to be available to the consumer in order to be processed correctly. This consumer will get a namespace to value map instead of each individual namespace and value as inaddAffixUpdateConsumer(Setting.AffixSetting, BiConsumer, BiConsumer)
-
addSettingsUpdateConsumer
Adds a settings consumer that accepts the values for two settings. SeeaddSettingsUpdateConsumer(Setting, Setting, BiConsumer, BiConsumer)
for details. -
addSettingsUpdateConsumer
public <A, B> void addSettingsUpdateConsumer(Setting<A> a, Setting<B> b, BiConsumer<A,B> consumer, BiConsumer<A,B> validator)Adds a settings consumer that accepts the values for two settings. The consumer is only notified if one or both settings change and if the provided validator succeeded.Note: Only settings registered in
This method registers a compound updater that is useful if two settings are depending on each other. The consumer is always provided with both values even if only one of the two changes.SettingsModule
can be changed dynamically. -
addSettingsUpdateConsumer
Adds a settings consumer.Note: Only settings registered in
ClusterModule
can be changed dynamically. -
validate
Validates that all settings are registered and valid.- Parameters:
settings
- the settings to validatevalidateValues
- true if values should be validated, otherwise only keys are validated- See Also:
Setting.getSettingsDependencies(String)
-
validate
public final void validate(Settings settings, boolean validateValues, boolean validateInternalOrPrivateIndex)Validates that all settings are registered and valid.- Parameters:
settings
- the settings to validatevalidateValues
- true if values should be validated, otherwise only keys are validatedvalidateInternalOrPrivateIndex
- true if internal index settings should be validated- See Also:
Setting.getSettingsDependencies(String)
-
validate
public final void validate(Settings settings, boolean validateValues, boolean ignorePrivateSettings, boolean ignoreArchivedSettings)Validates that all settings are registered and valid.- Parameters:
settings
- the settingsvalidateValues
- true if values should be validated, otherwise only keys are validatedignorePrivateSettings
- true if private settings should be ignored during validationignoreArchivedSettings
- true if archived settings should be ignored during validation- See Also:
Setting.getSettingsDependencies(String)
-
validate
public final void validate(Settings settings, boolean validateValues, boolean ignorePrivateSettings, boolean ignoreArchivedSettings, boolean validateInternalOrPrivateIndex)Validates that all settings are registered and valid.- Parameters:
settings
- the settingsvalidateValues
- true if values should be validated, otherwise only keys are validatedignorePrivateSettings
- true if private settings should be ignored during validationignoreArchivedSettings
- true if archived settings should be ignored during validationvalidateInternalOrPrivateIndex
- true if index internal settings should be validated- See Also:
Setting.getSettingsDependencies(String)
-
get
Returns theSetting
for the given key ornull
if the setting can not be found. -
isDynamicSetting
Returnstrue
if the setting for the given key is dynamically updateable. Otherwisefalse
. -
isFinalSetting
Returnstrue
if the setting for the given key is final. Otherwisefalse
. -
diff
Returns a settings object that contains all settings that are not already set in the given source. The diff contains either the default value for each setting or the settings value in the given default settings. -
get
Returns the value for the given setting. -
updateDynamicSettings
public boolean updateDynamicSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type)Updates a target settings builder with new, updated or deleted settings from a given settings builder.Note: This method will only allow updates to dynamic settings. if a non-dynamic setting is updated an
IllegalArgumentException
is thrown instead.- Parameters:
toApply
- the new settings to applytarget
- the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builderupdates
- a settings builder that holds all updates applied to targettype
- a free text string to allow better exceptions messages- Returns:
true
if the target has changed otherwisefalse
-
updateSettings
public boolean updateSettings(Settings toApply, Settings.Builder target, Settings.Builder updates, String type)Updates a target settings builder with new, updated or deleted settings from a given settings builder.- Parameters:
toApply
- the new settings to applytarget
- the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builderupdates
- a settings builder that holds all updates applied to targettype
- a free text string to allow better exceptions messages- Returns:
true
if the target has changed otherwisefalse
-
upgradeSettings
Upgrade all settings eligible for upgrade in the specified settings instance.- Parameters:
settings
- the settings instance that might contain settings to be upgraded- Returns:
- a new settings instance if any settings required upgrade, otherwise the same settings instance as specified
-
archiveUnknownOrInvalidSettings
public Settings archiveUnknownOrInvalidSettings(Settings settings, Consumer<Map.Entry<String,String>> unknownConsumer, BiConsumer<Map.Entry<String,String>,IllegalArgumentException> invalidConsumer)Archives invalid or unknown settings. Any setting that is not recognized or fails validation will be archived. This means the setting is prefixed with "archived." and remains in the settings object. This can be used to detect invalid settings via APIs.- Parameters:
settings
- theSettings
instance to scan for unknown or invalid settingsunknownConsumer
- callback on unknown settings (consumer receives unknown key and its associated value)invalidConsumer
- callback on invalid settings (consumer receives invalid key, its associated value and an exception)- Returns:
- a
Settings
instance with the unknown or invalid settings archived
-
isPrivateSetting
Returnstrue
iff the setting is a private setting ie. it should be treated as valid even though it has no internal representation. Otherwisefalse
-