Class UpdatingConfigSupplier<M extends net.morimekta.providence.PMessage<M,F>,F extends net.morimekta.providence.descriptor.PField>

  • 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.
    • Constructor Detail

      • UpdatingConfigSupplier

        protected UpdatingConfigSupplier​(@Nonnull
                                         java.time.Clock clock)
        Initialize supplier with empty config.
        Parameters:
        clock - The clock to use in timing config loads.
    • Method Detail

      • get

        @Nonnull
        public final M get()
        Specified by:
        get in interface java.util.function.Supplier<M extends net.morimekta.providence.PMessage<M,F>>
      • 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 interface ConfigSupplier<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 interface ConfigSupplier<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 interface ConfigSupplier<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.