Class AbstractScopedSettings

java.lang.Object
org.elasticsearch.common.settings.AbstractScopedSettings
Direct Known Subclasses:
ClusterSettings, IndexScopedSettings

public abstract class AbstractScopedSettings extends Object
A basic setting service that can be used for per-index and per-cluster settings. This service offers transactional application of updates settings.
  • Field Details

  • Constructor Details

  • Method Details

    • validateSettingKey

      protected void validateSettingKey(Setting<?> setting)
    • isValidKey

      public static boolean isValidKey(String key)
      Returns true iff the given key is a valid settings key otherwise false
    • getScope

      public Setting.Property getScope()
    • validateUpdate

      public Settings validateUpdate(Settings settings)
      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

      public Settings applySettings(Settings newSettings)
      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 SettingsModule can be changed dynamically.

      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.
    • 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 in addAffixUpdateConsumer(Setting.AffixSetting, BiConsumer, BiConsumer)
    • addSettingsUpdateConsumer

      public <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. See addSettingsUpdateConsumer(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 SettingsModule can be changed dynamically.

      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.
    • addSettingsUpdateConsumer

      public <T> void addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer)
      Adds a settings consumer.

      Note: Only settings registered in ClusterModule can be changed dynamically.

    • validate

      public final void validate(Settings settings, boolean validateValues)
      Validates that all settings are registered and valid.
      Parameters:
      settings - the settings to validate
      validateValues - 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 validate
      validateValues - true if values should be validated, otherwise only keys are validated
      validateInternalOrPrivateIndex - 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 settings
      validateValues - true if values should be validated, otherwise only keys are validated
      ignorePrivateSettings - true if private settings should be ignored during validation
      ignoreArchivedSettings - 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 settings
      validateValues - true if values should be validated, otherwise only keys are validated
      ignorePrivateSettings - true if private settings should be ignored during validation
      ignoreArchivedSettings - true if archived settings should be ignored during validation
      validateInternalOrPrivateIndex - true if index internal settings should be validated
      See Also:
      Setting.getSettingsDependencies(String)
    • get

      public final Setting<?> get(String key)
      Returns the Setting for the given key or null if the setting can not be found.
    • isDynamicSetting

      public boolean isDynamicSetting(String key)
      Returns true if the setting for the given key is dynamically updateable. Otherwise false.
    • isFinalSetting

      public boolean isFinalSetting(String key)
      Returns true if the setting for the given key is final. Otherwise false.
    • diff

      public Settings diff(Settings source, Settings defaultSettings)
      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

      public <T> T get(Setting<T> setting)
      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 apply
      target - the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder
      updates - a settings builder that holds all updates applied to target
      type - a free text string to allow better exceptions messages
      Returns:
      true if the target has changed otherwise false
    • 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 apply
      target - the target settings builder that the updates are applied to. All keys that have explicit null value in toApply will be removed from this builder
      updates - a settings builder that holds all updates applied to target
      type - a free text string to allow better exceptions messages
      Returns:
      true if the target has changed otherwise false
    • upgradeSettings

      public Settings upgradeSettings(Settings settings)
      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 - the Settings instance to scan for unknown or invalid settings
      unknownConsumer - 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

      public boolean isPrivateSetting(String key)
      Returns true iff the setting is a private setting ie. it should be treated as valid even though it has no internal representation. Otherwise false