Class ProfileConfigStore
- All Implemented Interfaces:
Closeable,AutoCloseable
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
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.juneau.marshall.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()copy()Creates a builder from this context object.static ProfileConfigStore.Buildercreate()Creates a new builder for this object.booleanChecks whether the configuration with the specified name exists in this store.getNotifiedContents(String name, String written) Returns the contents that listeners will be notified with after the specified contents are written.Returns the contents of the configuration file.Saves the contents of the configuration file if the underlying storage hasn't been modified.Methods inherited from class org.apache.juneau.config.store.ConfigStore
getMap, getMap, register, resolveName, unregister, update, updateMethods inherited from class org.apache.juneau.marshall.Context
createBuilder, createSession, getAnnotationProvider, getSession, init, isDebug, properties, toString
-
Constructor Details
-
ProfileConfigStore
Constructor.- Parameters:
builder- The builder for this object.
Cannot benull .
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
copy
Description copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
-
close
- Throws:
IOException
-
exists
Description copied from class:ConfigStoreChecks whether the configuration with the specified name exists in this store.- Specified by:
existsin classConfigStore- Parameters:
name- The config name.- Returns:
true if the configuration with the specified name exists in this store.
-
read
Description copied from class:ConfigStoreReturns the contents of the configuration file.- Specified by:
readin classConfigStore- Parameters:
name- The config file name.- Returns:
- The contents of the configuration file.
A blank string if the config does not exist.
Nevernull . - Throws:
IOException- Thrown by underlying stream.
-
write
Description copied from class:ConfigStoreSaves the contents of the configuration file if the underlying storage hasn't been modified.- Specified by:
writein classConfigStore- 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
Description copied from class:ConfigStoreReturns 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:
getNotifiedContentsin classConfigStore- 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.
-