Class FixedConfigSupplier<M extends net.morimekta.providence.PMessage<M>>
- java.lang.Object
-
- net.morimekta.providence.config.impl.FixedConfigSupplier<M>
-
- All Implemented Interfaces:
java.util.function.Supplier<M>,ConfigSupplier<M>
- Direct Known Subclasses:
ResourceConfigSupplier
@Immutable public class FixedConfigSupplier<M extends net.morimekta.providence.PMessage<M>> extends java.lang.Object implements ConfigSupplier<M>
A supplier and instance holder for an immutable config instance.
-
-
Constructor Summary
Constructors Constructor Description FixedConfigSupplier(M initialConfig)Initialize with an initial config instance.FixedConfigSupplier(M initialConfig, long timestamp, java.time.Clock clock)Initialize with an initial config instance.FixedConfigSupplier(ConfigSupplier<M> supplier)This essentially makes a static snapshot of the config and keeps the config instance as a fixed (unmodifiable) 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()java.lang.StringgetName()Get a simple descriptive name for this config supplier.<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.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.morimekta.providence.config.ConfigSupplier
override, override, snapshot
-
-
-
-
Constructor Detail
-
FixedConfigSupplier
public FixedConfigSupplier(@Nonnull M initialConfig)Initialize with an initial config instance.- Parameters:
initialConfig- The initial config instance.
-
FixedConfigSupplier
public FixedConfigSupplier(@Nonnull ConfigSupplier<M> supplier)This essentially makes a static snapshot of the config and keeps the config instance as a fixed (unmodifiable) config.- Parameters:
supplier- The config supplier to copy.
-
FixedConfigSupplier
public FixedConfigSupplier(@Nonnull M initialConfig, long timestamp, java.time.Clock clock)Initialize with an initial config instance.- Parameters:
initialConfig- The initial config instance.timestamp- The config timestamp.clock- Clock used to calculate timestamp.
-
-
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 final 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 final 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getName
public java.lang.String getName()
Description copied from interface:ConfigSupplierGet a simple descriptive name for this config supplier.- Specified by:
getNamein interfaceConfigSupplier<M extends net.morimekta.providence.PMessage<M>>- Returns:
- The supplier name.
-
-