Class SystemPropertySupplier<T>
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier<T>
-
- All Implemented Interfaces:
Supplier<T>
public class SystemPropertySupplier<T> extends Object implements Supplier<T>
Utility class for consistent handling of system properties.It provides for:
- TRACE level logging of getting the system property
- ERROR level logging when value does not parse or is invalid (where
validity can be checked by a
Predicate
) - (default) INFO level logging when value differs from default (log level and message format can be overridden)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <U> SystemPropertySupplier<U>
create(@NotNull String propName, U defaultValue)
Create it for a given property name and default value.SystemPropertySupplier<T>
formatSetMessage(@NotNull BiFunction<String,T,String> setMessageFormatter)
Specify a formatter for the "success" log message to be used when the returned property value differs from the default.T
get()
Obtains the value of a system property, optionally generating diagnostics.SystemPropertySupplier<T>
hideValue()
Used to hide property value in log messages (for instance, for passwords)SystemPropertySupplier<T>
loggingTo(@NotNull Logger log)
Specify theLogger
to log to (defaults to this classes logger otherwise).SystemPropertySupplier<T>
logSuccessAs(String successLogLevel)
SpecifyLevel
to use for "success" message (defaults to "INFO")protected SystemPropertySupplier<T>
usingSystemPropertyReader(@NotNull Function<String,String> sysPropReader)
For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String
).SystemPropertySupplier<T>
validateWith(@NotNull Predicate<T> validator)
Specify a validation expression.
-
-
-
Method Detail
-
create
public static <U> SystemPropertySupplier<U> create(@NotNull @NotNull String propName, @NotNull U defaultValue) throws IllegalArgumentException
Create it for a given property name and default value.- Throws:
IllegalArgumentException
-
loggingTo
public SystemPropertySupplier<T> loggingTo(@NotNull @NotNull Logger log)
Specify theLogger
to log to (defaults to this classes logger otherwise).
-
validateWith
public SystemPropertySupplier<T> validateWith(@NotNull @NotNull Predicate<T> validator)
Specify a validation expression.
-
formatSetMessage
public SystemPropertySupplier<T> formatSetMessage(@NotNull @NotNull BiFunction<String,T,String> setMessageFormatter)
Specify a formatter for the "success" log message to be used when the returned property value differs from the default.
-
logSuccessAs
public SystemPropertySupplier<T> logSuccessAs(String successLogLevel)
SpecifyLevel
to use for "success" message (defaults to "INFO")
-
hideValue
public SystemPropertySupplier<T> hideValue()
Used to hide property value in log messages (for instance, for passwords)Note: will have no effect when custom message formatter is used (see
setMessageFormatter
).
-
usingSystemPropertyReader
protected SystemPropertySupplier<T> usingSystemPropertyReader(@NotNull @NotNull Function<String,String> sysPropReader)
For unit testing: specify a function to read system properties (overriding default ofSystem.getProperty(String
).
-
-