Class 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 for com.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
    Each file should be one resource path per line, with blank lines ignored and lines beginning with '#' treated as comments.

    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 MConfig facade is the authoritative documentation for how config sources are discovered, layered, and prioritized, and is the supported entry point for acquiring configuration. The readVmConfig methods 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 on MConfig. See HoconPropertiesConfigSource for information on HOCON identifiers.

    • Constructor Detail

      • MultiPropertiesConfig

        public MultiPropertiesConfig()
    • 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)
      • 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 holding a.b.c=1 returns {a.b.c=1}, not {c=1}.

        A prefix matches by dot-separated token, never by character. So "a.b" reaches a.b.c and a.b.c.d, but not a.bx or a.b-x, which merely begin with the same letters. This is what the PropertiesConfig declaration means by asking that a prefix be a complete token.

        The prefix includes the exact key. A config holding only a.b=v answers getPropertiesByPrefix("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 as k.equals(baseKey) || k.startsWith(baseKey + "."). An implementation that filters on pfx + "." alone will disagree with BasicMultiPropertiesConfig, and so with the result of MConfig.combine(com.mchange.v2.cfg.MultiPropertiesConfig[]), which flattens everything it is given into one of those.

        Specified by:
        getPropertiesByPrefix in interface PropertiesConfig
        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:
        getProperty in interface PropertiesConfig
      • 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)