Class UpdatingConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
- java.lang.Object
-
- net.morimekta.providence.config.impl.UpdatingConfigSupplier<M,F>
-
- All Implemented Interfaces:
java.util.function.Supplier<M>
,ConfigSupplier<M,F>
- Direct Known Subclasses:
OverrideConfigSupplier
,ProvidenceConfigSupplier
,ReferenceConfigSupplier
,TestConfigSupplier
public abstract class UpdatingConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField> extends java.lang.Object implements ConfigSupplier<M,F>
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 protected
UpdatingConfigSupplier(java.time.Clock clock)
Initialize supplier with empty config.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ConfigListener<M,F> listener)
Add a listener to changes to this config.long
configTimestamp()
Get the last update time as a millisecond timestamp.M
get()
void
removeListener(ConfigListener<M,F> listener)
Remove a config change listener.protected void
set(M config)
Set a new config value to the supplier.-
Methods inherited from interface net.morimekta.providence.config.ConfigSupplier
getName, snapshot
-
-
-
-
Method Detail
-
get
@Nonnull public final M get()
-
addListener
public void addListener(@Nonnull ConfigListener<M,F> listener)
Description copied from interface:ConfigSupplier
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.- Specified by:
addListener
in interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
- Parameters:
listener
- The config change listener to be added.
-
removeListener
public void removeListener(@Nonnull ConfigListener<M,F> listener)
Description copied from interface:ConfigSupplier
Remove a config change listener.- Specified by:
removeListener
in interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
- Parameters:
listener
- The config change listener to be removed.
-
configTimestamp
public long configTimestamp()
Description copied from interface:ConfigSupplier
Get the last update time as a millisecond timestamp.- Specified by:
configTimestamp
in interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
- Returns:
- The timestamp of last update of the config.
-
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.
-
-