@ThreadSafe public class OptionsMap extends Object implements Serializable
DriverConfigLoader.fromMap(OptionsMap)
.
This class is intended for clients who wish to assemble the driver configuration in memory,
instead of loading it from configuration files. Note that driverDefaults()
can be used
to pre-initialize the map with the driver's built-in defaults.
It functions like a two-dimensional map indexed by execution profile and option. All methods
have a profile-less variant that applies to the default profile, for example get(String,
TypedDriverOption)
and get(TypedDriverOption)
. Options are represented by TypedDriverOption
, which allows this class to enforce additional type-safety guarantees (an
option can only be set to a value of its intended type).
This class is mutable and thread-safe. Live changes are reflected in real time to the driver session(s) that use this configuration.
Constructor and Description |
---|
OptionsMap() |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(Consumer<OptionsMap> listener)
Registers a listener that will get notified when this object changes.
|
protected Map<String,Map<DriverOption,Object>> |
asRawMap()
Returns a live view of this object, using the driver's untyped
DriverOption . |
static OptionsMap |
driverDefaults()
Creates a new instance that contains the driver's default configuration.
|
boolean |
equals(Object other) |
protected static void |
fillWithDriverDefaults(OptionsMap map) |
<ValueT> ValueT |
get(String profile,
TypedDriverOption<ValueT> option)
Returns the value to which the specified option is mapped in the specified profile, or
null if the option is not defined. |
<ValueT> ValueT |
get(TypedDriverOption<ValueT> option)
Returns the value to which the specified option is mapped in the default profile, or
null if the option is not defined. |
int |
hashCode() |
<ValueT> ValueT |
put(String profile,
TypedDriverOption<ValueT> option,
ValueT value)
Associates the specified value for the specified option, in the specified execution profile.
|
<ValueT> ValueT |
put(TypedDriverOption<ValueT> option,
ValueT value)
Associates the specified value for the specified option, in the default execution profile.
|
<ValueT> ValueT |
remove(String profile,
TypedDriverOption<ValueT> option)
Removes the specified option from the specified profile.
|
<ValueT> ValueT |
remove(TypedDriverOption<ValueT> option)
Removes the specified option from the default profile.
|
boolean |
removeChangeListener(Consumer<OptionsMap> listener)
Unregisters a listener that was previously registered with
addChangeListener(Consumer) . |
@NonNull public static OptionsMap driverDefaults()
This will produce a configuration that is equivalent to the reference.conf
file
bundled with the driver (however, this method does not load any file, and doesn't require
Typesafe config in the classpath).
@Nullable public <ValueT> ValueT put(@NonNull String profile, @NonNull TypedDriverOption<ValueT> option, @NonNull ValueT value)
option
, or null
if the option was
not defined.@Nullable public <ValueT> ValueT put(@NonNull TypedDriverOption<ValueT> option, @NonNull ValueT value)
option
, or null
if the option was
not defined.@Nullable public <ValueT> ValueT get(@NonNull String profile, @NonNull TypedDriverOption<ValueT> option)
null
if the option is not defined.@Nullable public <ValueT> ValueT get(@NonNull TypedDriverOption<ValueT> option)
null
if the option is not defined.@Nullable public <ValueT> ValueT remove(@NonNull String profile, @NonNull TypedDriverOption<ValueT> option)
option
, or null
if the option was
not defined.@Nullable public <ValueT> ValueT remove(@NonNull TypedDriverOption<ValueT> option)
option
, or null
if the option was
not defined.public void addChangeListener(@NonNull Consumer<OptionsMap> listener)
This is mostly for internal use by the driver. Note that listeners are transient, and not
taken into account by equals(Object)
and hashCode()
.
public boolean removeChangeListener(@NonNull Consumer<OptionsMap> listener)
addChangeListener(Consumer)
.true
if the listener was indeed registered for this object.@NonNull protected Map<String,Map<DriverOption,Object>> asRawMap()
DriverOption
.
This is intended for internal usage by the driver. Modifying the resulting map is strongly discouraged, as it could break the type-safety guarantees provided by the public methods.
protected static void fillWithDriverDefaults(OptionsMap map)
Copyright © 2017–2024. All rights reserved.