java.lang.Object
org.elasticsearch.common.settings.Settings
- All Implemented Interfaces:
Diffable<Settings>,Writeable,ToXContent,ToXContentFragment
public final class Settings
extends Object
implements ToXContentFragment, Writeable, Diffable<Settings>
An immutable settings implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder allowing to put different settings and thenSettings.Builder.build()an immutable settings implementation.Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.ParamsNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Settingsstatic final Stringstatic final ToXContent.MapParamsFields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS -
Method Summary
Modifier and TypeMethodDescriptionstatic Settings.Builderbuilder()Returns a builder to be used in order to build settings.Returns serializable object representing differences between this and previousStatebooleanReturns a new settings object that contains all setting of the current one filtered by the given settings key predicate.static SettingsfromXContent(XContentParser parser) Parsers the generated xcontent fromtoXContent(XContentBuilder, Params)into a new Settings object.Returns the setting value associated with the setting key.Returns the setting value associated with the setting key.getAsBoolean(String setting, Boolean defaultValue) Returns the setting value (as boolean) associated with the setting key.getAsBytesSize(String setting, ByteSizeValue defaultValue) Returns the setting value (as size) associated with the setting key.getAsDouble(String setting, Double defaultValue) Returns the setting value (as double) associated with the setting key.getAsFloat(String setting, Float defaultValue) Returns the setting value (as float) associated with the setting key.Returns group settings for the given setting prefix.Returns the setting value (as int) associated with the setting key.The values associated with a setting key as an immutable list.The values associated with a setting key as an immutable list.The values associated with a setting key as an immutable list.Returns the setting value (as long) associated with the setting key.getAsMemory(String setting, String defaultValue) Returns the setting value (as size) associated with the setting key.getAsSettings(String setting) Returns the settings mapped to the given setting name.Returns the setting value (as time) associated with the setting key.<T extends VersionId<T>>
TgetAsVersionId(String setting, IntFunction<T> parseVersion) Returns a parsed version.<T extends VersionId<T>>
TgetAsVersionId(String setting, IntFunction<T> parseVersion, T defaultVersion) Returns a parsed version.getByPrefix(String prefix) A settings that are filtered (and key is removed) with the specified prefix.Returns group settings for the given setting prefix.Returns group settings for the given setting prefix.Returns the values for the given settings pattern.inthashCode()booleanReturnstrueiff the given key has a value in this settings objectstatic StringInterns the given string which should be either a setting key or value or part of a setting value list.booleanisEmpty()Returnstrueif this settings object contains no settingskeySet()Returns the fully qualified setting names contained in this settings object.names()static Settingsintsize()Returns the number of settings in this settings object.toDelimitedString(char delimiter) Returns the settings as delimited string.toString()toXContent(XContentBuilder builder, ToXContent.Params params) voidwriteTo(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
-
Field Details
-
EMPTY
-
FLAT_SETTINGS_PARAM
- See Also:
-
FLAT_SETTINGS_TRUE
-
FORMAT_PARAMS
-
-
Method Details
-
getByPrefix
A settings that are filtered (and key is removed) with the specified prefix. -
filter
Returns a new settings object that contains all setting of the current one filtered by the given settings key predicate. -
getAsSettings
Returns the settings mapped to the given setting name. -
get
Returns the setting value associated with the setting key.- Parameters:
setting- The setting key- Returns:
- The setting value,
nullif it does not exists.
-
get
Returns the setting value associated with the setting key. If it does not exists, returns the default value provided. -
getValues
Returns the values for the given settings pattern. Either a concrete setting name, or a pattern containing a single glob is supported.- Parameters:
settingPattern- name of a setting or a setting name pattern containing a glob- Returns:
- zero or more values for any settings in this settings object that match the given pattern
-
getAsFloat
Returns the setting value (as float) associated with the setting key. If it does not exists, returns the default value provided. -
getAsDouble
Returns the setting value (as double) associated with the setting key. If it does not exists, returns the default value provided. -
getAsInt
Returns the setting value (as int) associated with the setting key. If it does not exists, returns the default value provided. -
getAsLong
Returns the setting value (as long) associated with the setting key. If it does not exists, returns the default value provided. -
hasValue
Returnstrueiff the given key has a value in this settings object -
getAsBoolean
Returns the setting value (as boolean) associated with the setting key. If it does not exists, returns the default value provided. -
getAsTime
Returns the setting value (as time) associated with the setting key. If it does not exists, returns the default value provided. -
getAsBytesSize
public ByteSizeValue getAsBytesSize(String setting, ByteSizeValue defaultValue) throws SettingsException Returns the setting value (as size) associated with the setting key. If it does not exists, returns the default value provided.- Throws:
SettingsException
-
getAsMemory
Returns the setting value (as size) associated with the setting key. Provided values can either be absolute values (interpreted as a number of bytes), byte sizes (eg. 1mb) or percentage of the heap size (eg. 12%). If it does not exists, parses the default value provided.- Throws:
SettingsException
-
getAsList
The values associated with a setting key as an immutable list.It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list by- Returns:
- The setting list values
- Throws:
SettingsException
-
getAsList
The values associated with a setting key as an immutable list.If commaDelimited is true, it will automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list by- Returns:
- The setting list values
- Throws:
SettingsException
-
getAsList
public List<String> getAsList(String key, List<String> defaultValue, Boolean commaDelimited) throws SettingsException The values associated with a setting key as an immutable list.It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list bydefaultValue- The default value to use if no value is specifiedcommaDelimited- Whether to try to parse a string as a comma-delimited value- Returns:
- The setting list values
- Throws:
SettingsException
-
getGroups
Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getGroups
public Map<String,Settings> getGroups(String settingPrefix, boolean ignoreNonGrouped) throws SettingsException Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getAsGroups
Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getAsVersionId
public <T extends VersionId<T>> T getAsVersionId(String setting, IntFunction<T> parseVersion) throws SettingsException Returns a parsed version.- Throws:
SettingsException
-
getAsVersionId
public <T extends VersionId<T>> T getAsVersionId(String setting, IntFunction<T> parseVersion, T defaultVersion) throws SettingsException Returns a parsed version.- Throws:
SettingsException
-
names
- Returns:
- The direct keys of this settings
-
toDelimitedString
Returns the settings as delimited string. -
equals
-
hashCode
public int hashCode() -
readSettingsFromStream
- Throws:
IOException
-
readSettingsDiffFromStream
- Throws:
IOException
-
diff
Description copied from interface:DiffableReturns serializable object representing differences between this and previousState -
writeTo
Description copied from interface:WriteableWrite this into the StreamOutput.- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
builder
Returns a builder to be used in order to build settings. -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContentin interfaceToXContent- Throws:
IOException
-
fromXContent
Parsers the generated xcontent fromtoXContent(XContentBuilder, Params)into a new Settings object. Note this method requires the parser to either be positioned on a null token or onXContentParser.Token.START_OBJECT.- Throws:
IOException
-
isEmpty
public boolean isEmpty()Returnstrueif this settings object contains no settings- Returns:
trueif this settings object contains no settings
-
size
public int size()Returns the number of settings in this settings object. -
keySet
Returns the fully qualified setting names contained in this settings object. -
toString
-
internKeyOrValue
Interns the given string which should be either a setting key or value or part of a setting value list. This is used to reduce the memory footprint of similar setting instances like index settings that may contain mostly the same keys and values. Interning these strings at some runtime cost is considered a reasonable trade-off here since neither setting keys nor values change frequently while duplicate keys values may consume significant amounts of memory.- Parameters:
s- string to intern- Returns:
- interned string
-