Package net.morimekta.providence.config
Class FixedConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>
- java.lang.Object
-
- net.morimekta.providence.config.FixedConfigSupplier<M,F>
-
- All Implemented Interfaces:
java.util.function.Supplier<M>,ConfigSupplier<M,F>
- Direct Known Subclasses:
ResourceConfigSupplier
@Immutable public class FixedConfigSupplier<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 an immutable config instance.
-
-
Constructor Summary
Constructors Constructor Description FixedConfigSupplier(M initialConfig)Initialize with an initial config instance.FixedConfigSupplier(M initialConfig, long timestamp)Initialize with an initial config instance.FixedConfigSupplier(ConfigSupplier<M,F> 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,F> listener)Add a listener to changes to this config.longconfigTimestamp()Get the last update time as a millisecond timestamp.Mget()java.lang.StringgetName()Get a simple descriptive name for this config supplier.voidremoveListener(ConfigListener<M,F> listener)Remove a config change listener.java.lang.StringtoString()-
Methods inherited from interface net.morimekta.providence.config.ConfigSupplier
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,F> 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)Initialize with an initial config instance.- Parameters:
initialConfig- The initial config instance.timestamp- The config timestamp.
-
-
Method Detail
-
get
@Nonnull public final M get()
-
addListener
public final void addListener(@Nonnull ConfigListener<M,F> 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,F>,F extends net.morimekta.providence.descriptor.PField>- Parameters:
listener- The config change listener to be added.
-
removeListener
public final void removeListener(@Nonnull ConfigListener<M,F> listener)Description copied from interface:ConfigSupplierRemove a config change listener.- Specified by:
removeListenerin 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:ConfigSupplierGet the last update time as a millisecond timestamp.- Specified by:
configTimestampin 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.
-
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.
-
-