Class MultiPropertiesConfig
- java.lang.Object
-
- com.mchange.v2.cfg.MultiPropertiesConfig
-
- All Implemented Interfaces:
PropertiesConfig
- Direct Known Subclasses:
HoconMultiPropertiesConfig
public abstract class MultiPropertiesConfig extends java.lang.Object implements PropertiesConfig
MultiPropertiesConfig allows applications to accept configuration data from a more than one property file (each of which is to be loaded from a unique path using this class' ClassLoader's resource-loading mechanism), and permits access to property data via the resource path from which the properties were loaded, via the prefix of the property (where hierarchical property names are presumed to be '.'-separated), and simply by key. In the by-key and by-prefix indices, when two definitions conflict, the key value pairing specified in the MOST RECENT properties file shadows earlier definitions, and files are loaded in the order of the list of resource paths provided a constructor. The resource path "/" is a special case that always refers to System properties. No actual resource will be loaded. If a HOCON implementation (lightbend/typesafe config, detected by probing forcom.typesafe.config.Config) is available on the CLASSPATH, resource paths specified as "hocon:/path/to/resource" will be parsed as HOCON, whenever values can be interpreted as Strings. When no such implementation is present, those paths are skipped with a FINE-level log item.Traditionally the library resolved a default ("vmConfig") list of resource paths from text files, themselves ClassLoader-managed resources, read and concatenated in this order:
/com/mchange/v2/cfg/vmConfigResourcePaths.txt/mchange-config-resource-paths.txt
If none of those text files is available, or none of them yields any path, the following resources are checked instead: "/mchange-commons.properties", "hocon:/reference,/application,/", "/"
The
MConfigfacade is the authoritative documentation for how config sources are discovered, layered, and prioritized, and is the supported entry point for acquiring configuration. ThereadVmConfigmethods on this class are deprecated; note also that they resolve paths by a different algorithm and cache into a different store than the identically named methods onMConfig. See HoconPropertiesConfigSource for information on HOCON identifiers.
-
-
Constructor Summary
Constructors Constructor Description MultiPropertiesConfig()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static MultiPropertiesConfigfromProperties(java.lang.String notionalResourcePath, java.util.Properties props)static MultiPropertiesConfigfromProperties(java.util.Properties props)abstract java.util.Set<java.lang.String>getAllFaults()abstract java.util.Set<java.lang.String>getAllNotFound()abstract java.util.Set<java.lang.String>getAllRead()abstract java.util.Set<java.lang.String>getAllVetoed()abstract java.util.List<DelayedLogItem>getDelayedLogItems()abstract java.util.PropertiesgetPropertiesByPrefix(java.lang.String pfx)The Properties beneath a prefix, keyed by full key rather than by the remainder after the prefix.abstract java.util.PropertiesgetPropertiesByResourcePath(java.lang.String path)abstract java.lang.String[]getPropertiesResourcePaths()abstract java.lang.StringgetProperty(java.lang.String key)static MultiPropertiesConfigreadVmConfig()Deprecated.Please use the MConfig facade class to acquire configurationstatic MultiPropertiesConfigreadVmConfig(java.lang.String[] defaultResources, java.lang.String[] preemptingResources)Deprecated.Please use the MConfig facade class to acquire configurationbooleanwasEncountered(java.lang.String resourcePath)abstract booleanwasFault(java.lang.String resourcePath)abstract booleanwasNotFound(java.lang.String resourcePath)abstract booleanwasRead(java.lang.String resourcePath)abstract booleanwasVetoed(java.lang.String resourcePath)
-
-
-
Method Detail
-
readVmConfig
@Deprecated public static MultiPropertiesConfig readVmConfig(java.lang.String[] defaultResources, java.lang.String[] preemptingResources)
Deprecated.Please use the MConfig facade class to acquire configuration
-
readVmConfig
@Deprecated public static MultiPropertiesConfig readVmConfig()
Deprecated.Please use the MConfig facade class to acquire configuration
-
fromProperties
public static MultiPropertiesConfig fromProperties(java.lang.String notionalResourcePath, java.util.Properties props)
-
fromProperties
public static MultiPropertiesConfig fromProperties(java.util.Properties props)
-
getPropertiesResourcePaths
public abstract java.lang.String[] getPropertiesResourcePaths()
-
getPropertiesByResourcePath
public abstract java.util.Properties getPropertiesByResourcePath(java.lang.String path)
- Returns:
- an empty Properties, even if path is unknown, just to avoid downstream NullPointerExceptions
-
getPropertiesByPrefix
public abstract java.util.Properties getPropertiesByPrefix(java.lang.String pfx)
The Properties beneath a prefix, keyed by full key rather than by the remainder after the prefix.getPropertiesByPrefix("a.b")over a config holdinga.b.c=1returns{a.b.c=1}, not{c=1}.A prefix matches by dot-separated token, never by character. So
"a.b"reachesa.b.canda.b.c.d, but nota.bxora.b-x, which merely begin with the same letters. This is what thePropertiesConfigdeclaration means by asking that a prefix be a complete token.The prefix includes the exact key. A config holding only
a.b=vanswersgetPropertiesByPrefix("a.b")with{a.b=v}, not with an empty Properties: every key is a prefix of itself. The consequence worth knowing is that a non-empty result does not by itself mean the prefix names a populated scope — it may be one bare key wearing the scope's name. Where the distinction matters, ask for it:Properties under = cfg.getPropertiesByPrefix( pfx ); boolean bareKeySet = under.containsKey( pfx ); // or getProperty(pfx) != null boolean hasSubkeys = under.size() > (bareKeySet ? 1 : 0);The special prefix
""returns all the Properties. A key with no dot in it is reachable only under""and under itself.Implementors: the exact key belongs in the result. The in-library consumer that walks a prefix's keys is
WhitelistManager, whose fallback path over live System properties spells the same rule out ask.equals(baseKey) || k.startsWith(baseKey + "."). An implementation that filters onpfx + "."alone will disagree withBasicMultiPropertiesConfig, and so with the result ofMConfig.combine(com.mchange.v2.cfg.MultiPropertiesConfig[]), which flattens everything it is given into one of those.- Specified by:
getPropertiesByPrefixin interfacePropertiesConfig- Returns:
- an empty Properties, even if prefix is unknown, just to avoid downstream NullPointerExceptions
-
getProperty
public abstract java.lang.String getProperty(java.lang.String key)
- Specified by:
getPropertyin interfacePropertiesConfig
-
getDelayedLogItems
public abstract java.util.List<DelayedLogItem> getDelayedLogItems()
-
wasRead
public abstract boolean wasRead(java.lang.String resourcePath)
-
wasVetoed
public abstract boolean wasVetoed(java.lang.String resourcePath)
-
wasNotFound
public abstract boolean wasNotFound(java.lang.String resourcePath)
-
wasFault
public abstract boolean wasFault(java.lang.String resourcePath)
-
getAllRead
public abstract java.util.Set<java.lang.String> getAllRead()
-
getAllVetoed
public abstract java.util.Set<java.lang.String> getAllVetoed()
-
getAllNotFound
public abstract java.util.Set<java.lang.String> getAllNotFound()
-
getAllFaults
public abstract java.util.Set<java.lang.String> getAllFaults()
-
wasEncountered
public boolean wasEncountered(java.lang.String resourcePath)
-
-