Class Setting<T>

java.lang.Object
org.elasticsearch.common.settings.Setting<T>
All Implemented Interfaces:
org.elasticsearch.xcontent.ToXContent, org.elasticsearch.xcontent.ToXContentObject
Direct Known Subclasses:
SecureSetting, Setting.AffixSetting

public class Setting<T> extends Object implements org.elasticsearch.xcontent.ToXContentObject
A setting. Encapsulates typical stuff like default value, parsing, and scope. Some (SettingsProperty.Dynamic) can by modified at run time using the API. All settings inside elasticsearch or in any of the plugins should use this type-safe and generic settings infrastructure together with AbstractScopedSettings. This class contains several utility methods that makes it straight forward to add settings for the majority of the cases. For instance a simple boolean settings can be defined like this:

 public static final Setting<Boolean>; MY_BOOLEAN = Setting.boolSetting("my.bool.setting", true, SettingsProperty.NodeScope);
 
To retrieve the value of the setting a Settings object can be passed directly to the get(Settings) method.
 final boolean myBooleanValue = MY_BOOLEAN.get(settings);
 
It's recommended to use typed settings rather than string based settings. For example adding a setting for an enum type:

 public enum Color {
     RED, GREEN, BLUE;
 }
 public static final Setting<Color> MY_BOOLEAN =
     new Setting<>("my.color.setting", Color.RED.toString(), Color::valueOf, SettingsProperty.NodeScope);
 
 
  • Field Details

  • Constructor Details

    • Setting

      public Setting(Setting.Key key, Function<Settings,String> defaultValue, Function<String,T> parser, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      defaultValue - a default value function that returns the default values string representation.
      parser - a parser that parses the string rep into a complex datatype.
      properties - properties for this setting like scope, filtering...
    • Setting

      public Setting(Setting.Key key, Function<Settings,String> defaultValue, Function<String,T> parser, Setting.Validator<T> validator, Setting.Property... properties)
      Creates a new Setting instance.
      Parameters:
      key - the settings key for this setting
      defaultValue - a default value function that results a string representation of the default value
      parser - a parser that parses a string representation into the concrete type for this setting
      validator - a Setting.Validator for validating this setting
      properties - properties for this setting
    • Setting

      public Setting(String key, String defaultValue, Function<String,T> parser, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      defaultValue - a default value.
      parser - a parser that parses the string rep into a complex datatype.
      properties - properties for this setting like scope, filtering...
    • Setting

      public Setting(String key, String defaultValue, Function<String,T> parser, Setting.Validator<T> validator, Setting.Property... properties)
      Creates a new Setting instance.
      Parameters:
      key - the settings key for this setting
      defaultValue - a default value function that results a string representation of the default value
      parser - a parser that parses a string representation into the concrete type for this setting
      validator - a Setting.Validator for validating this setting
      properties - properties for this setting
    • Setting

      public Setting(String key, Function<Settings,String> defaultValue, Function<String,T> parser, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      defaultValue - a default value function that returns the default values string representation.
      parser - a parser that parses the string rep into a complex datatype.
      properties - properties for this setting like scope, filtering...
    • Setting

      public Setting(String key, Setting<T> fallbackSetting, Function<String,T> parser, Setting.Validator<T> validator, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      fallbackSetting - a setting who's value to fallback on if this setting is not defined
      parser - a parser that parses the string rep into a complex datatype.
      validator - a Setting.Validator for validating this setting
      properties - properties for this setting like scope, filtering...
    • Setting

      public Setting(Setting.Key key, Setting<T> fallbackSetting, Function<String,T> parser, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      fallbackSetting - a setting who's value to fallback on if this setting is not defined
      parser - a parser that parses the string rep into a complex datatype.
      properties - properties for this setting like scope, filtering...
    • Setting

      public Setting(String key, Setting<T> fallBackSetting, Function<String,T> parser, Setting.Property... properties)
      Creates a new Setting instance
      Parameters:
      key - the settings key for this setting.
      fallBackSetting - a setting to fall back to if the current setting is not set.
      parser - a parser that parses the string rep into a complex datatype.
      properties - properties for this setting like scope, filtering...
  • Method Details