Class PropertyPlaceholderResolver

java.lang.Object
org.jmxtrans.embedded.util.json.PropertyPlaceholderResolver
All Implemented Interfaces:
Serializable

public class PropertyPlaceholderResolver
extends Object
implements Serializable
Inspired by Spring Property placeholder mechanism. Placeholders are delimited by '{' and '}' and support default value with ':'. Sample : '{graphite.host}' or '{graphite.port:2003}'. If the placeholder is not found in the system properties, it is searched in the environment variables and then converted to underscore delimited upper case and searched in environment variables. Sample for '{graphite.port:2003}':
  1. System.getProperty("graphite.port")
  2. System.getenv("graphite.port")
  3. System.getenv("GRAPHITE_PORT")
  4. default to 2003
Author:
Cyrille Le Clerc
See Also:
Serialized Form
  • Constructor Details

    • PropertyPlaceholderResolver

      public PropertyPlaceholderResolver()
  • Method Details

    • resolveString

      @Nonnull public String resolveString​(@Nonnull String string) throws EmbeddedJmxTransException
      Parse the given string resolving property placeholders (${my-property[:default-value]})
      Parameters:
      string - the string to parse.
      Returns:
      the parsed string.
      Throws:
      EmbeddedJmxTransException - a property placeholder could not be resolved and no default value has been defined.
    • resolvePlaceholder

      @Nonnull protected String resolvePlaceholder​(String property, @Nullable String defaultValue) throws EmbeddedJmxTransException
      Search for the given placeholder in system properties then in environment variables.
      Parameters:
      property - property to resolve
      defaultValue - Default value if the placeholder is not found. null means not default value is defined and the placeholder must exist
      Returns:
      the resolved property or the default value if the placeholder is not found and the default value is defined
      Throws:
      EmbeddedJmxTransException - if the placeholder is not found and the given defaultValue is not defined (null)