Class ProfileConfigStore

All Implemented Interfaces:
Closeable, AutoCloseable

public class ProfileConfigStore extends ConfigStore
A ConfigStore decorator that layers profile overlays over a delegate store's base config.

Given a set of active profiles (e.g. ["stage"] or ["base","cloud"]) and a base config name N, a read(N) returns the base contents from the delegate with each active profile's N-<profile> overlay merged on top — profile wins over base, last-active-profile wins over earlier ones (see ProfileMerge). Reads for any name other than the configured base name pass straight through to the delegate.

Live reload: the store registers a listener on the delegate for the base name and each profile name, so a change to the base file or any active profile file re-runs the merge and re-fires the change to this store's own listeners (the ConfigMap sees a fresh merged contents and reloads).

The profile file name is derived from the base name by inserting -<profile> before the extension (e.g. base my.cfg + profile stage → my-stage.cfg); a base with no extension simply appends -<profile>. Writes, existence checks, and name resolution delegate to the wrapped store.

Since:
10.0.0
  • Constructor Details

  • Method Details

    • create

      Creates a new builder for this object.
      Returns:
      A new builder.
    • copy

      Description copied from class: Context
      Creates a builder from this context object.

      Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.

      Overrides:
      copy in class Context
      Returns:
      A new Builder object.
    • close

      public void close() throws IOException
      Throws:
      IOException
    • exists

      public boolean exists(String name)
      Description copied from class: ConfigStore
      Checks whether the configuration with the specified name exists in this store.
      Specified by:
      exists in class ConfigStore
      Parameters:
      name - The config name.
      Returns:
      true if the configuration with the specified name exists in this store.
    • read

      public String read(String name) throws IOException
      Description copied from class: ConfigStore
      Returns the contents of the configuration file.
      Specified by:
      read in class ConfigStore
      Parameters:
      name - The config file name.
      Returns:
      The contents of the configuration file.
      A blank string if the config does not exist.
      Never null.
      Throws:
      IOException - Thrown by underlying stream.
    • write

      public String write(String name, String expectedContents, String newContents) throws IOException
      Description copied from class: ConfigStore
      Saves the contents of the configuration file if the underlying storage hasn't been modified.
      Specified by:
      write in class ConfigStore
      Parameters:
      name - The config file name.
      expectedContents - The expected contents of the file.
      newContents - The new contents.
      Returns:
      If null, then we successfully stored the contents of the file.
      Otherwise the contents of the file have changed and we return the new contents of the file.
      Throws:
      IOException - Thrown by underlying stream.
    • getNotifiedContents

      public String getNotifiedContents(String name, String written) throws IOException
      Description copied from class: ConfigStore
      Returns the contents that listeners will be notified with after the specified contents are written.

      Stores that notify listeners with text other than what was written (e.g. after merging in overlays) should override this method.

      This is called before the write, so any processing that fails (e.g. merging unparseable written text) fails before anything is persisted.

      Overrides:
      getNotifiedContents in class ConfigStore
      Parameters:
      name - The config name.
      written - The contents being written.
      Returns:
      The contents that listeners will receive. The default implementation returns written.
      Throws:
      IOException - Thrown by underlying stream.