- All Superinterfaces:
JStachioExtension
Runtime Config Service.
While a majority of jstachio config is static and done at compile time some config like logging and disabling extensions is needed at runtime. Config and DI agnostic extensions should use this facility for simple key value based config.
The default resolved config uses System properties but can be replaced by implementing this extension.
- Author:
- agentgt
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
getBoolean
(String key) default boolean
getBoolean
(String key, boolean fallback) Gets the property as a boolean and if no property value is found the fallback is used.default System.Logger
Gets a system logger if the propertyLOGGING_DISABLE
isfalse
.@Nullable String
getProperty
(String key) Gets a property from some config implementation.static System.Logger
NOOP Logger that will not trigger initialization of the SystemSystem.Logger
facilities.default String
requireProperty
(String key, String fallback) A NonNull friendly analog ofSystem.getProperty(String, String)
that will never return null unlike System.getProperty which is PolyNull.
-
Field Details
-
REFLECTION_TEMPLATE_DISABLE
Config key to disable reflection based lookup of templates for other fallback mechanisms- See Also:
-
LOGGING_DISABLE
Config key to disable if logging. By default logging is enabled.- See Also:
-
-
Method Details
-
getProperty
Gets a property from some config implementation.- Parameters:
key
- the key to use to lookup- Returns:
- if not found
null
.
-
getBoolean
- Parameters:
key
- the property key- Returns:
- only true if string is "true"
-
getBoolean
Gets the property as a boolean and if no property value is found the fallback is used.- Parameters:
key
- property keyfallback
- if property has no value this value is used.- Returns:
- the parsed boolean or the fallback
-
requireProperty
A NonNull friendly analog ofSystem.getProperty(String, String)
that will never return null unlike System.getProperty which is PolyNull.- Parameters:
key
- checked if null and will NPE immediatly if it isfallback
- used if the retrieved property is null- Returns:
- property or fallback if property is not found (
null
). - Throws:
NullPointerException
- if the fallback is null or if the key is null.
-
getLogger
Gets a system logger if the propertyLOGGING_DISABLE
isfalse
. If the property is set to atrue
value a NOOP Logger that will not trigger initialization of the SystemSystem.Logger
facilities will be returned. The NOOP logger is always disabled at every level and will not produce any output.- Parameters:
name
- the name of the logger usually the class.- Returns:
- the System logger.
- See Also:
-
noopLogger
NOOP Logger that will not trigger initialization of the SystemSystem.Logger
facilities. The NOOP logger is always disabled at every level and will not produce any output.Extensions might find this useful to set a nonnull Logger field like:
private Logger logger = JStacheConfig.noopLogger(); public void init(JStacheConfig config) { logger = config.getLogger(getClass().getName()); }
- Returns:
- singleton instance of noop logger
-