@Public public class Configuration extends ExecutionConfig.GlobalJobParameters implements IOReadableWritable, Serializable, Cloneable, ReadableConfig, WritableConfig
Modifier and Type | Field and Description |
---|---|
protected HashMap<String,Object> |
confData
Stores the concrete key/value pairs of this configuration object.
|
protected boolean |
standardYaml |
Constructor and Description |
---|
Configuration()
Creates a new empty configuration.
|
Configuration(boolean standardYaml) |
Configuration(Configuration other)
Creates a new configuration with the copy of the given configuration.
|
Modifier and Type | Method and 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 this
Configuration to the given Properties . |
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 of
getRawValueFromOption(ConfigOption) . |
<T> T |
get(ConfigOption<T> configOption,
T overrideDefault)
Returns the value associated with the given config option as a T.
|
boolean |
getBoolean(ConfigOption<Boolean> configOption)
Deprecated.
|
boolean |
getBoolean(ConfigOption<Boolean> configOption,
boolean overrideDefault)
Deprecated.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Deprecated.
|
byte[] |
getBytes(String key,
byte[] defaultValue)
Returns the value associated with the given key as a byte array.
|
<T> Class<T> |
getClass(String key,
Class<? extends T> defaultValue,
ClassLoader classLoader)
Deprecated.
|
double |
getDouble(ConfigOption<Double> configOption)
Deprecated.
|
double |
getDouble(ConfigOption<Double> configOption,
double overrideDefault)
Deprecated.
|
double |
getDouble(String key,
double defaultValue)
Deprecated.
|
<T extends Enum<T>> |
getEnum(Class<T> enumClass,
ConfigOption<String> configOption)
Returns the value associated with the given config option as an enum.
|
float |
getFloat(ConfigOption<Float> configOption)
Deprecated.
|
float |
getFloat(ConfigOption<Float> configOption,
float overrideDefault)
Deprecated.
|
float |
getFloat(String key,
float defaultValue)
Deprecated.
|
int |
getInteger(ConfigOption<Integer> configOption)
Deprecated.
|
int |
getInteger(ConfigOption<Integer> configOption,
int overrideDefault)
Deprecated.
|
int |
getInteger(String key,
int defaultValue)
Deprecated.
|
long |
getLong(ConfigOption<Long> configOption)
Deprecated.
|
long |
getLong(ConfigOption<Long> configOption,
long overrideDefault)
Deprecated.
|
long |
getLong(String key,
long defaultValue)
Deprecated.
|
<T> Optional<T> |
getOptional(ConfigOption<T> option)
Reads a value using the metadata included in
ConfigOption . |
String |
getString(ConfigOption<String> configOption)
Deprecated.
|
String |
getString(ConfigOption<String> configOption,
String overrideDefault)
Deprecated.
|
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 the
ConfigOption . |
void |
setBoolean(ConfigOption<Boolean> key,
boolean value)
Deprecated.
|
void |
setBoolean(String key,
boolean value)
Deprecated.
|
void |
setBytes(String key,
byte[] bytes)
Adds the given byte array to the configuration object.
|
void |
setClass(String key,
Class<?> klazz)
Deprecated.
|
void |
setDouble(ConfigOption<Double> key,
double value)
Deprecated.
|
void |
setDouble(String key,
double value)
Deprecated.
|
void |
setFloat(ConfigOption<Float> key,
float value)
Deprecated.
|
void |
setFloat(String key,
float value)
Deprecated.
|
void |
setInteger(ConfigOption<Integer> key,
int value)
Deprecated.
|
void |
setInteger(String key,
int value)
Deprecated.
|
void |
setLong(ConfigOption<Long> key,
long value)
Deprecated.
|
void |
setLong(String key,
long value)
Deprecated.
|
void |
setString(ConfigOption<String> key,
String value)
Deprecated.
|
void |
setString(String key,
String value)
Adds the given key/value pair to the configuration object.
|
Map<String,String> |
toFileWritableMap()
Convert Config into a
Map<String, String> representation. |
Map<String,String> |
toMap()
Convert UserConfig into a
Map<String, String> representation. |
String |
toString() |
void |
write(DataOutputView out)
Writes the object's internal data to the given data output view.
|
protected final HashMap<String,Object> confData
NOTE: This map stores the values that are actually used, and does not include any escaping that is required by the standard YAML syntax.
protected final boolean standardYaml
public Configuration()
@VisibleForTesting @Internal public Configuration(boolean standardYaml)
public Configuration(Configuration other)
other
- The configuration to copy the entries from.public static Configuration fromMap(Map<String,String> map)
@Deprecated public <T> Class<T> getClass(String key, Class<? extends T> defaultValue, ClassLoader classLoader) throws ClassNotFoundException
T
- The type of the class to return.key
- The key pointing to the associated valuedefaultValue
- The optional default value returned if no entry existsclassLoader
- The class loader used to resolve the class.ClassNotFoundException
@Deprecated public void setClass(String key, Class<?> klazz)
getClass(String, Class, ClassLoader)
if it is in the scope of the class
loader on the caller.key
- The key of the pair to be addedklazz
- The value of the pair to be addedgetClass(String, Class, ClassLoader)
public String getString(String key, String defaultValue)
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@Deprecated @PublicEvolving public String getString(ConfigOption<String> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
configOption
- The configuration option@Deprecated @PublicEvolving public String getString(ConfigOption<String> configOption, String overrideDefault)
get(ConfigOption, Object)
configOption
- The configuration optionpublic void setString(String key, String value)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setString(ConfigOption<String> key, String value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be added@Deprecated public int getInteger(String key, int defaultValue)
get(ConfigOption)
, get(ConfigOption, Object)
or getOptional(ConfigOption)
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@Deprecated @PublicEvolving public int getInteger(ConfigOption<Integer> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
configOption
- The configuration option@Deprecated @PublicEvolving public int getInteger(ConfigOption<Integer> configOption, int overrideDefault)
get(ConfigOption, Object)
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option@Deprecated public void setInteger(String key, int value)
set(ConfigOption, Object)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setInteger(ConfigOption<Integer> key, int value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be added@Deprecated public long getLong(String key, long defaultValue)
get(ConfigOption)
, get(ConfigOption, Object)
or getOptional(ConfigOption)
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@Deprecated @PublicEvolving public long getLong(ConfigOption<Long> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
configOption
- The configuration option@Deprecated @PublicEvolving public long getLong(ConfigOption<Long> configOption, long overrideDefault)
get(ConfigOption, Object)
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option@Deprecated public void setLong(String key, long value)
set(ConfigOption, Object)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setLong(ConfigOption<Long> key, long value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be added@Deprecated public boolean getBoolean(String key, boolean defaultValue)
get(ConfigOption)
, get(ConfigOption, Object)
or getOptional(ConfigOption)
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@Deprecated @PublicEvolving public boolean getBoolean(ConfigOption<Boolean> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
configOption
- The configuration option@Deprecated @PublicEvolving public boolean getBoolean(ConfigOption<Boolean> configOption, boolean overrideDefault)
get(ConfigOption, Object)
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option@Deprecated public void setBoolean(String key, boolean value)
set(ConfigOption, Object)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setBoolean(ConfigOption<Boolean> key, boolean value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be added@Deprecated public float getFloat(String key, float defaultValue)
get(ConfigOption)
, get(ConfigOption, Object)
or getOptional(ConfigOption)
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@Deprecated @PublicEvolving public float getFloat(ConfigOption<Float> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
configOption
- The configuration option@Deprecated @PublicEvolving public float getFloat(ConfigOption<Float> configOption, float overrideDefault)
get(ConfigOption, Object)
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option@Deprecated public void setFloat(String key, float value)
set(ConfigOption, Object)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setFloat(ConfigOption<Float> key, float value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be added@Deprecated public double getDouble(String key, double defaultValue)
get(ConfigOption)
, get(ConfigOption, Object)
or getOptional(ConfigOption)
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@Deprecated @PublicEvolving public double getDouble(ConfigOption<Double> configOption)
get(ConfigOption)
or getOptional(ConfigOption)
double
.configOption
- The configuration option@Deprecated @PublicEvolving public double getDouble(ConfigOption<Double> configOption, double overrideDefault)
get(ConfigOption, Object)
double
. If no value is
mapped under any key of the option, it returns the specified default instead of the option's
default value.configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the option@Deprecated public void setDouble(String key, double value)
set(ConfigOption, Object)
key
- the key of the key/value pair to be addedvalue
- the value of the key/value pair to be added@Deprecated @PublicEvolving public void setDouble(ConfigOption<Double> key, double value)
set(ConfigOption, Object)
key
- the option specifying the key to be addedvalue
- the value of the key/value pair to be addedpublic byte[] getBytes(String key, byte[] defaultValue)
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.public void setBytes(String key, byte[] bytes)
null
then
nothing is added.key
- The key under which the bytes are added.bytes
- The bytes to be added.@PublicEvolving public String getValue(ConfigOption<?> configOption)
configOption
- The configuration option@PublicEvolving public <T extends Enum<T>> T getEnum(Class<T> enumClass, ConfigOption<String> configOption)
enumClass
- The return enum classconfigOption
- The configuration optionIllegalArgumentException
- If the string associated with the given config option cannot
be parsed as a value of the provided enum class.public Set<String> keySet()
public void addAllToProperties(Properties props)
Configuration
to the given Properties
.public void addAll(Configuration other)
public void addAll(Configuration other, String prefix)
other
- The configuration whose entries are added to this configuration.prefix
- The prefix to prepend.public Configuration clone()
public boolean containsKey(String key)
key
- key of entry@PublicEvolving public boolean contains(ConfigOption<?> configOption)
configOption
- The configuration optionpublic <T> T get(ConfigOption<T> option)
getRawValueFromOption(ConfigOption)
. If no keys are
found in Configuration
, 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.
get
in interface ReadableConfig
T
- type of the value to readoption
- metadata of the option to readReadableConfig.getOptional(ConfigOption)
@PublicEvolving public <T> T get(ConfigOption<T> configOption, T overrideDefault)
configOption
- The configuration optionoverrideDefault
- The value to return if no value was mapper for any key of the optionpublic <T> Optional<T> getOptional(ConfigOption<T> option)
ReadableConfig
ConfigOption
. In contrast to ReadableConfig.get(ConfigOption)
returns Optional.empty()
if value not present.getOptional
in interface ReadableConfig
T
- type of the value to readoption
- metadata of the option to readOptional.empty()
if not foundReadableConfig.get(ConfigOption)
public <T> Configuration set(ConfigOption<T> option, T value)
WritableConfig
ConfigOption
. The value
should be readable back through ReadableConfig
.set
in interface WritableConfig
T
- type of the value to be storedoption
- metadata informationvalue
- value to be storedpublic Map<String,String> toMap()
ExecutionConfig.GlobalJobParameters
Map<String, String>
representation. This can be used by
the runtime, for example for presenting the user config in the web frontend.toMap
in interface ReadableConfig
toMap
in class ExecutionConfig.GlobalJobParameters
@Internal public Map<String,String> toFileWritableMap()
Map<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.
public <T> boolean removeConfig(ConfigOption<T> configOption)
T
- Type of the config optionconfigOption
- config option to removepublic boolean removeKey(String key)
key
- key of a config option to removepublic void read(DataInputView in) throws IOException
IOReadableWritable
read
in interface IOReadableWritable
in
- the input view to read the data fromIOException
- thrown if any error occurs while reading from the input streampublic void write(DataOutputView out) throws IOException
IOReadableWritable
write
in interface IOReadableWritable
out
- the output view to receive the data.IOException
- thrown if any error occurs while writing to the output streampublic int hashCode()
hashCode
in class ExecutionConfig.GlobalJobParameters
public boolean equals(Object obj)
equals
in class ExecutionConfig.GlobalJobParameters
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.