Class UpdatingConfigSupplier<M extends net.morimekta.providence.PMessage<M>>
- java.lang.Object
-
- net.morimekta.providence.config.impl.UpdatingConfigSupplier<M>
-
- All Implemented Interfaces:
java.util.function.Supplier<M>,ConfigSupplier<M>
- Direct Known Subclasses:
OverrideConfigSupplier,ProvidenceConfigSupplier,ReferenceConfigSupplier,TestConfigSupplier
public abstract class UpdatingConfigSupplier<M extends net.morimekta.providence.PMessage<M>> extends java.lang.Object implements ConfigSupplier<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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedUpdatingConfigSupplier(java.time.Clock clock)Initialize supplier with empty config.
-
Method Summary
All Methods Instance Methods Concrete 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.Mget()java.time.ClockgetClock()<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.protected voidset(M config)Set a new config value to the supplier.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.morimekta.providence.config.ConfigSupplier
getName, override, override, snapshot
-
-
-
-
Method Detail
-
get
@Nonnull public final M get()
-
reference
public <RM extends net.morimekta.providence.PMessage<RM>> ConfigSupplier<RM> reference(net.morimekta.providence.descriptor.PField... fields) throws ConfigException
Description copied from interface:ConfigSupplierGive a reference to a sub-config based on field selection.- Specified by:
referencein interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Type Parameters:
RM- The resulting config type.- Parameters:
fields- The fields to select.- Returns:
- The reference config supplier.
- Throws:
ConfigException- If resolving fields failed
-
addListener
public void addListener(@Nonnull ConfigListener<M> listener)Description copied from interface:ConfigSupplierAdd 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.- Specified by:
addListenerin interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Parameters:
listener- The config change listener to be added.
-
removeListener
public void removeListener(@Nonnull ConfigListener<M> listener)Description copied from interface:ConfigSupplierRemove a config change listener.- Specified by:
removeListenerin interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Parameters:
listener- The config change listener to be removed.
-
configTimestamp
public long configTimestamp()
Description copied from interface:ConfigSupplierGet the last update time as a millisecond timestamp.- Specified by:
configTimestampin interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Returns:
- The timestamp of last update of the config.
-
getClock
public java.time.Clock getClock()
- Specified by:
getClockin interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Returns:
- Get the clock used to calculate config timestamp.
-
set
protected final void set(M config)
Set a new config value to the supplier. This is protected as it is usually up to the supplier implementation to enable updating the config at later stages.- Parameters:
config- The new config instance.
-
-