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)

The supported types are: Boolean, Integer, Long, String

  • Method Details

    • 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 the Logger 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)
      Specify Level 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 of System.getProperty(String).
    • get

      public T get()
      Obtains the value of a system property, optionally generating diagnostics.
      Specified by:
      get in interface Supplier<T>
      Returns:
      value of system property