Package net.morimekta.providence.config
Interface ConfigSupplier<M extends net.morimekta.providence.PMessage<M>>
-
- All Superinterfaces:
java.util.function.Supplier<M>
- All Known Implementing Classes:
FixedConfigSupplier,OverrideConfigSupplier,ProvidenceConfigSupplier,ReferenceConfigSupplier,ResourceConfigSupplier,TestConfigSupplier,UpdatingConfigSupplier
public interface ConfigSupplier<M extends net.morimekta.providence.PMessage<M>> extends java.util.function.Supplier<M>A supplier and instance holder for config objects. This supplier can be listened to for changes in the config object. When something triggers a change (supplier.set(config)) that will cause a config change call to each listener regardless of if the config values actually did change.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddListener(ConfigListener<M> listener)Add a listener to changes to this config.longconfigTimestamp()Get the last update time as a millisecond timestamp.java.time.ClockgetClock()java.lang.StringgetName()Get a simple descriptive name for this config supplier.default ConfigSupplier<M>override(java.util.Map<java.lang.String,java.lang.String> overrides)Get config with single-field overrides based on the current config.default ConfigSupplier<M>override(java.util.Map<java.lang.String,java.lang.String> overrides, boolean strict)Get config with single-field overrides based on the current config.<RM extends net.morimekta.providence.PMessage<RM>>
ConfigSupplier<RM>reference(net.morimekta.providence.descriptor.PField... fields)Give a reference to a sub-config based on field selection.voidremoveListener(ConfigListener<M> listener)Remove a config change listener.default ConfigSupplier<M>snapshot()Get a snapshot of the current config.
-
-
-
Method Detail
-
reference
<RM extends net.morimekta.providence.PMessage<RM>> ConfigSupplier<RM> reference(net.morimekta.providence.descriptor.PField... fields) throws ConfigException
Give a reference to a sub-config based on field selection.- Type Parameters:
RM- The resulting config type.- Parameters:
fields- The fields to select.- Returns:
- The reference config supplier.
- Throws:
ConfigException- If resolving fields failed
-
override
default ConfigSupplier<M> override(java.util.Map<java.lang.String,java.lang.String> overrides) throws ConfigException
Get config with single-field overrides based on the current config.- Parameters:
overrides- Map of field value overrides.- Returns:
- Config with overrides.
- Throws:
ConfigException- If the overrides are invalid.
-
override
default ConfigSupplier<M> override(java.util.Map<java.lang.String,java.lang.String> overrides, boolean strict) throws ConfigException
Get config with single-field overrides based on the current config.- Parameters:
overrides- Map of field value overrides.strict- If the overrides should be checked strictly.- Returns:
- Config with overrides.
- Throws:
ConfigException- If the overrides are invalid.
-
snapshot
default ConfigSupplier<M> snapshot()
Get a snapshot of the current config.- Returns:
- Non-modifiable supplier of current config containing a snapshot.
-
addListener
void addListener(@Nonnull ConfigListener<M> listener)Add a listener to changes to this config. Note that this will store a weak reference to the listener instance, so the one adding the listener must make sure the listener is not GC'd.- Parameters:
listener- The config change listener to be added.
-
removeListener
void removeListener(@Nonnull ConfigListener<M> listener)Remove a config change listener.- Parameters:
listener- The config change listener to be removed.
-
getName
java.lang.String getName()
Get a simple descriptive name for this config supplier.- Returns:
- The supplier name.
-
configTimestamp
long configTimestamp()
Get the last update time as a millisecond timestamp.- Returns:
- The timestamp of last update of the config.
-
getClock
java.time.Clock getClock()
- Returns:
- Get the clock used to calculate config timestamp.
-
-