Package org.apache.flink.configuration
Class Configuration
- java.lang.Object
-
- org.apache.flink.api.common.ExecutionConfig.GlobalJobParameters
-
- org.apache.flink.configuration.Configuration
-
- All Implemented Interfaces:
Serializable
,Cloneable
,ReadableConfig
,WritableConfig
,IOReadableWritable
- Direct Known Subclasses:
DelegatingConfiguration
,UnmodifiableConfiguration
@Public public class Configuration extends ExecutionConfig.GlobalJobParameters implements IOReadableWritable, Serializable, Cloneable, ReadableConfig, WritableConfig
Lightweight configuration object which stores key/value pairs.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Configuration()
Creates a new empty configuration.Configuration(Configuration other)
Creates a new configuration with the copy of the given configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(Configuration other)
void
addAll(Configuration other, String prefix)
Adds all entries from the given configuration into this configuration.void
addAllToProperties(Properties props)
Adds all entries in thisConfiguration
to the givenProperties
.Configuration
clone()
boolean
contains(ConfigOption<?> configOption)
Checks whether there is an entry for the given config option.boolean
containsKey(String key)
Checks whether there is an entry with the specified key.boolean
equals(Object obj)
static Configuration
fromMap(Map<String,String> map)
Creates a new configuration that is initialized with the options of the given map.<T> T
get(ConfigOption<T> option)
Please check the java doc ofgetRawValueFromOption(ConfigOption)
.<T> T
get(ConfigOption<T> configOption, T overrideDefault)
Returns the value associated with the given config option as a T.byte[]
getBytes(String key, byte[] defaultValue)
Returns the value associated with the given key as a byte array.<T extends Enum<T>>
TgetEnum(Class<T> enumClass, ConfigOption<String> configOption)
Returns the value associated with the given config option as an enum.<T> Optional<T>
getOptional(ConfigOption<T> option)
Reads a value using the metadata included inConfigOption
.String
getString(String key, String defaultValue)
Returns the value associated with the given key as a string.String
getValue(ConfigOption<?> configOption)
Returns the value associated with the given config option as a string.int
hashCode()
Set<String>
keySet()
Returns the keys of all key/value pairs stored inside this configuration object.void
read(DataInputView in)
Reads the object's internal data from the given data input view.<T> boolean
removeConfig(ConfigOption<T> configOption)
Removes given config option from the configuration.boolean
removeKey(String key)
Removes given key from the configuration.<T> Configuration
set(ConfigOption<T> option, T value)
Stores a given value using the metadata included in theConfigOption
.void
setBytes(String key, byte[] bytes)
Adds the given byte array to the configuration object.void
setString(String key, String value)
Adds the given key/value pair to the configuration object.Map<String,String>
toFileWritableMap()
Convert Config into aMap<String, String>
representation.Map<String,String>
toMap()
Convert UserConfig into aMap<String, String>
representation.String
toString()
void
write(DataOutputView out)
Writes the object's internal data to the given data output view.
-
-
-
Constructor Detail
-
Configuration
public Configuration()
Creates a new empty configuration.
-
Configuration
public Configuration(Configuration other)
Creates a new configuration with the copy of the given configuration.- Parameters:
other
- The configuration to copy the entries from.
-
-
Method Detail
-
fromMap
public static Configuration fromMap(Map<String,String> map)
Creates a new configuration that is initialized with the options of the given map.
-
getString
public String getString(String key, String defaultValue)
Returns the value associated with the given key as a string. We encourage users and developers to always use ConfigOption for getting the configurations if possible, for its rich description, type, default-value and other supports. The string-key-based getter should only be used when ConfigOption is not applicable, e.g., the key is programmatically generated in runtime.- Parameters:
key
- the key pointing to the associated valuedefaultValue
- the default value which is returned in case there is no value associated with the given key- Returns:
- the (default) value associated with the given key
-
setString
public void setString(String key, String value)
Adds the given key/value pair to the configuration object. We encourage users and developers to always use ConfigOption for setting the configurations if possible, for its rich description, type, default-value and other supports. The string-key-based setter should only be used when ConfigOption is not applicable, e.g., the key is programmatically generated in runtime.- Parameters:
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added
-
getBytes
@Internal public byte[] getBytes(String key, byte[] defaultValue)
Returns the value associated with the given key as a byte array.- Parameters:
key
- The key pointing to the associated value.defaultValue
- The default value which is returned in case there is no value associated with the given key.- Returns:
- the (default) value associated with the given key.
-
setBytes
@Internal public void setBytes(String key, byte[] bytes)
Adds the given byte array to the configuration object. If key isnull
then nothing is added.- Parameters:
key
- The key under which the bytes are added.bytes
- The bytes to be added.
-
getValue
@PublicEvolving public String getValue(ConfigOption<?> configOption)
Returns the value associated with the given config option as a string.- Parameters:
configOption
- The configuration option- Returns:
- the (default) value associated with the given config option
-
getEnum
@PublicEvolving public <T extends Enum<T>> T getEnum(Class<T> enumClass, ConfigOption<String> configOption)
Returns the value associated with the given config option as an enum.- Parameters:
enumClass
- The return enum classconfigOption
- The configuration option- Throws:
IllegalArgumentException
- If the string associated with the given config option cannot be parsed as a value of the provided enum class.
-
keySet
public Set<String> keySet()
Returns the keys of all key/value pairs stored inside this configuration object.- Returns:
- the keys of all key/value pairs stored inside this configuration object
-
addAllToProperties
public void addAllToProperties(Properties props)
Adds all entries in thisConfiguration
to the givenProperties
.
-
addAll
public void addAll(Configuration other)
-
addAll
public void addAll(Configuration other, String prefix)
Adds all entries from the given configuration into this configuration. The keys are prepended with the given prefix.- Parameters:
other
- The configuration whose entries are added to this configuration.prefix
- The prefix to prepend.
-
clone
public Configuration clone()
-
containsKey
public boolean containsKey(String key)
Checks whether there is an entry with the specified key.- Parameters:
key
- key of entry- Returns:
- true if the key is stored, false otherwise
-
contains
@PublicEvolving public boolean contains(ConfigOption<?> configOption)
Checks whether there is an entry for the given config option.- Parameters:
configOption
- The configuration option- Returns:
- true if a valid (current or deprecated) key of the config option is stored, false otherwise
-
get
public <T> T get(ConfigOption<T> option)
Please check the java doc ofgetRawValueFromOption(ConfigOption)
. If no keys are found inConfiguration
, default value of the given option will return. Please make sure there will be at least one value available. Otherwise, a NPE will be thrown by Flink when the value is used.NOTE: current logic is not able to get the default value of the fallback key's ConfigOption, in case the given ConfigOption has no default value. If you want to use fallback key, please make sure its value could be found in
Configuration
at runtime.- Specified by:
get
in interfaceReadableConfig
- Type Parameters:
T
- type of the value to read- Parameters:
option
- metadata of the option to read- Returns:
- the value of the given option
- See Also:
ReadableConfig.getOptional(ConfigOption)
-
get
@PublicEvolving public <T> T get(ConfigOption<T> configOption, T overrideDefault)
Returns the value associated with the given config option as a T. If no value is mapped under any key of the option, it returns the specified default instead of the option's default value.- Parameters:
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option- Returns:
- the configured value associated with the given config option, or the overrideDefault
-
getOptional
public <T> Optional<T> getOptional(ConfigOption<T> option)
Description copied from interface:ReadableConfig
Reads a value using the metadata included inConfigOption
. In contrast toReadableConfig.get(ConfigOption)
returnsOptional.empty()
if value not present.- Specified by:
getOptional
in interfaceReadableConfig
- Type Parameters:
T
- type of the value to read- Parameters:
option
- metadata of the option to read- Returns:
- read value or
Optional.empty()
if not found - See Also:
ReadableConfig.get(ConfigOption)
-
set
public <T> Configuration set(ConfigOption<T> option, T value)
Description copied from interface:WritableConfig
Stores a given value using the metadata included in theConfigOption
. The value should be readable back throughReadableConfig
.- Specified by:
set
in interfaceWritableConfig
- Type Parameters:
T
- type of the value to be stored- Parameters:
option
- metadata informationvalue
- value to be stored- Returns:
- instance of this configuration for fluent API
-
toMap
public Map<String,String> toMap()
Description copied from class:ExecutionConfig.GlobalJobParameters
Convert UserConfig into aMap<String, String>
representation. This can be used by the runtime, for example for presenting the user config in the web frontend.- Specified by:
toMap
in interfaceReadableConfig
- Overrides:
toMap
in classExecutionConfig.GlobalJobParameters
- Returns:
- Key/Value representation of the UserConfig
-
toFileWritableMap
@Internal public Map<String,String> toFileWritableMap()
Convert Config into aMap<String, String>
representation.NOTE: This method is extracted from the
toMap()
method and should be called when Config needs to be written to a file.This method ensures the value is properly escaped when writing the key-value pair to a standard YAML file.
-
removeConfig
public <T> boolean removeConfig(ConfigOption<T> configOption)
Removes given config option from the configuration.- Type Parameters:
T
- Type of the config option- Parameters:
configOption
- config option to remove- Returns:
- true is config has been removed, false otherwise
-
removeKey
public boolean removeKey(String key)
Removes given key from the configuration.- Parameters:
key
- key of a config option to remove- Returns:
- true is config has been removed, false otherwise
-
read
public void read(DataInputView in) throws IOException
Description copied from interface:IOReadableWritable
Reads the object's internal data from the given data input view.- Specified by:
read
in interfaceIOReadableWritable
- Parameters:
in
- the input view to read the data from- Throws:
IOException
- thrown if any error occurs while reading from the input stream
-
write
public void write(DataOutputView out) throws IOException
Description copied from interface:IOReadableWritable
Writes the object's internal data to the given data output view.- Specified by:
write
in interfaceIOReadableWritable
- Parameters:
out
- the output view to receive the data.- Throws:
IOException
- thrown if any error occurs while writing to the output stream
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classExecutionConfig.GlobalJobParameters
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classExecutionConfig.GlobalJobParameters
-
-