Class AbstractScopedSettings

  • Direct Known Subclasses:
    ClusterSettings, IndexScopedSettings

    public abstract class AbstractScopedSettings
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ARCHIVED_SETTINGS_PREFIX  
      protected org.apache.logging.log4j.Logger logger  
    • Method Summary

      Modifier and Type Method Description
      void addAffixGroupUpdateConsumer​(java.util.List<Setting.AffixSetting<?>> settings, java.util.function.BiConsumer<java.lang.String,​Settings> consumer)
      Adds a affix settings consumer that accepts the settings for a group of settings.
      <T> void addAffixMapUpdateConsumer​(Setting.AffixSetting<T> setting, java.util.function.Consumer<java.util.Map<java.lang.String,​T>> consumer, java.util.function.BiConsumer<java.lang.String,​T> validator)
      Adds a settings consumer for affix settings.
      <A,​B>
      void
      addAffixUpdateConsumer​(Setting.AffixSetting<A> settingA, Setting.AffixSetting<B> settingB, java.util.function.BiConsumer<java.lang.String,​Tuple<A,​B>> consumer, java.util.function.BiConsumer<java.lang.String,​Tuple<A,​B>> validator)
      Adds a affix settings consumer that accepts the values for two settings.
      <T> void addAffixUpdateConsumer​(Setting.AffixSetting<T> setting, java.util.function.BiConsumer<java.lang.String,​T> consumer, java.util.function.BiConsumer<java.lang.String,​T> validator)
      Adds a settings consumer for affix settings.
      void addSettingsUpdateConsumer​(java.util.function.Consumer<Settings> consumer, java.util.List<? extends Setting<?>> settings)
      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, java.util.function.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, java.util.function.BiConsumer<A,​B> consumer, java.util.function.BiConsumer<A,​B> validator)
      Adds a settings consumer that accepts the values for two settings.
      <T> void addSettingsUpdateConsumer​(Setting<T> setting, java.util.function.Consumer<T> consumer)
      Adds a settings consumer.
      <T> void addSettingsUpdateConsumer​(Setting<T> setting, java.util.function.Consumer<T> consumer, java.util.function.Consumer<T> validator)
      Adds a settings consumer with a predicate that is only evaluated at update time.
      Settings applySettings​(Settings newSettings)
      Applies the given settings to all the settings consumers or to none of them.
      Settings archiveUnknownOrInvalidSettings​(Settings settings, java.util.function.Consumer<java.util.Map.Entry<java.lang.String,​java.lang.String>> unknownConsumer, java.util.function.BiConsumer<java.util.Map.Entry<java.lang.String,​java.lang.String>,​java.lang.IllegalArgumentException> invalidConsumer)
      Archives invalid or unknown settings.
      Settings diff​(Settings source, Settings defaultSettings)
      Returns a settings object that contains all settings that are not already set in the given source.
      Setting<?> get​(java.lang.String key)
      Returns the Setting for the given key or null if the setting can not be found.
      <T> T get​(Setting<T> setting)
      Returns the value for the given setting.
      Setting.Property getScope()  
      boolean isDynamicSetting​(java.lang.String key)
      Returns true if the setting for the given key is dynamically updateable.
      boolean isFinalSetting​(java.lang.String key)
      Returns true if the setting for the given key is final.
      boolean isPrivateSetting​(java.lang.String key)
      Returns true iff the setting is a private setting ie.
      static boolean isValidKey​(java.lang.String key)
      Returns true iff the given key is a valid settings key otherwise false
      boolean updateDynamicSettings​(Settings toApply, Settings.Builder target, Settings.Builder updates, java.lang.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, java.lang.String type)
      Updates a target settings builder with new, updated or deleted settings from a given settings builder.
      Settings upgradeSettings​(Settings settings)
      Upgrade all settings eligible for upgrade in the specified settings instance.
      void validate​(Settings settings, boolean validateDependencies)
      Validates that all settings are registered and valid.
      void validate​(Settings settings, boolean validateDependencies, boolean validateInternalOrPrivateIndex)
      Validates that all settings are registered and valid.
      void validate​(Settings settings, boolean validateDependencies, boolean ignorePrivateSettings, boolean ignoreArchivedSettings)
      Validates that all settings are registered and valid.
      void validate​(Settings settings, boolean validateDependencies, boolean ignorePrivateSettings, boolean ignoreArchivedSettings, boolean validateInternalOrPrivateIndex)
      Validates that all settings are registered and valid.
      protected void validateSettingKey​(Setting<?> setting)  
      Settings validateUpdate​(Settings settings)
      Validates the given settings by running it through all update listeners without applying it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ARCHIVED_SETTINGS_PREFIX

        public static final java.lang.String ARCHIVED_SETTINGS_PREFIX
        See Also:
        Constant Field Values
      • logger

        protected final org.apache.logging.log4j.Logger logger
    • Method Detail

      • validateSettingKey

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

        public static boolean isValidKey​(java.lang.String key)
        Returns true iff the given key is a valid settings key otherwise false
      • 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,
                                                  java.util.function.Consumer<T> consumer,
                                                  java.util.function.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​(java.util.function.Consumer<Settings> consumer,
                                              java.util.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
      • addAffixUpdateConsumer

        public <T> void addAffixUpdateConsumer​(Setting.AffixSetting<T> setting,
                                               java.util.function.BiConsumer<java.lang.String,​T> consumer,
                                               java.util.function.BiConsumer<java.lang.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,
                                                       java.util.function.BiConsumer<java.lang.String,​Tuple<A,​B>> consumer,
                                                       java.util.function.BiConsumer<java.lang.String,​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​(java.util.List<Setting.AffixSetting<?>> settings,
                                                java.util.function.BiConsumer<java.lang.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,
                                                  java.util.function.Consumer<java.util.Map<java.lang.String,​T>> consumer,
                                                  java.util.function.BiConsumer<java.lang.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,
                                                          java.util.function.BiConsumer<A,​B> consumer,
                                                          java.util.function.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,
                                                  java.util.function.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 validateDependencies)
        Validates that all settings are registered and valid.
        Parameters:
        settings - the settings to validate
        validateDependencies - true if dependent settings should be validated
        See Also:
        Setting.getSettingsDependencies(String)
      • validate

        public final void validate​(Settings settings,
                                   boolean validateDependencies,
                                   boolean validateInternalOrPrivateIndex)
        Validates that all settings are registered and valid.
        Parameters:
        settings - the settings to validate
        validateDependencies - true if dependent settings should be validated
        validateInternalOrPrivateIndex - true if internal index settings should be validated
        See Also:
        Setting.getSettingsDependencies(String)
      • validate

        public final void validate​(Settings settings,
                                   boolean validateDependencies,
                                   boolean ignorePrivateSettings,
                                   boolean ignoreArchivedSettings)
        Validates that all settings are registered and valid.
        Parameters:
        settings - the settings
        validateDependencies - true if dependent settings should be 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 validateDependencies,
                                   boolean ignorePrivateSettings,
                                   boolean ignoreArchivedSettings,
                                   boolean validateInternalOrPrivateIndex)
        Validates that all settings are registered and valid.
        Parameters:
        settings - the settings
        validateDependencies - true if dependent settings should be 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​(java.lang.String key)
        Returns the Setting for the given key or null if the setting can not be found.
      • isDynamicSetting

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

        public boolean isFinalSetting​(java.lang.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,
                                             java.lang.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,
                                      java.lang.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,
                                                        java.util.function.Consumer<java.util.Map.Entry<java.lang.String,​java.lang.String>> unknownConsumer,
                                                        java.util.function.BiConsumer<java.util.Map.Entry<java.lang.String,​java.lang.String>,​java.lang.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​(java.lang.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