Class Config


  • public abstract class Config
    extends Object
    Represents the global agent configuration consisting of system properties, environment variables, contents of the agent configuration file and properties defined by the ConfigPropertySource SPI (see ConfigInitializer and ConfigBuilder).

    In case any get*() method variant gets called for the same property more than once (e.g. each time an advice class executes) it is suggested to cache the result instead of repeatedly calling Config. Agent configuration does not change during the runtime so retrieving the property once and storing its result in e.g. static final field allows JIT to do its magic and remove some code branches.

    • Method Detail

      • internalInitializeConfig

        public static void internalInitializeConfig​(Config config)
        Sets the agent configuration singleton. This method is only supposed to be called once, from the agent classloader just before the first instrumentation is loaded (and before get() is used for the first time).
      • get

        public static Config get()
        Returns the global agent configuration.
      • getAllProperties

        public abstract Map<String,​String> getAllProperties()
        Returns all properties stored in this instance. The returned map is unmodifiable.
      • getString

        @Nullable
        public String getString​(String name)
        Returns a string-valued configuration property or null if a property with name name has not been configured.
      • getString

        public String getString​(String name,
                                String defaultValue)
        Returns a string-valued configuration property or defaultValue if a property with name name has not been configured.
      • getBoolean

        public boolean getBoolean​(String name,
                                  boolean defaultValue)
        Returns a boolean-valued configuration property or defaultValue if a property with name name has not been configured.
      • getInt

        public int getInt​(String name,
                          int defaultValue)
        Returns a integer-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. This is the safe variant of getInt(String).
      • getLong

        public long getLong​(String name,
                            long defaultValue)
        Returns a long-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. This is the safe variant of getLong(String).
      • getDouble

        public double getDouble​(String name,
                                double defaultValue)
        Returns a double-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. This is the safe variant of getDouble(String).
      • getDuration

        @Deprecated
        @Nullable
        public Duration getDuration​(String name)
        Deprecated.
        Use the getDuration(String, Duration) variant instead.
        Returns a duration-valued configuration property or null if a property with name name has not been configured.

        Durations can be of the form "{number}{unit}", where unit is one of:

        • ms
        • s
        • m
        • h
        • d

        If no unit is specified, milliseconds is the assumed duration unit.

        Throws:
        ConfigParsingException - if the property is not a valid long.
      • getDuration

        public Duration getDuration​(String name,
                                    Duration defaultValue)
        Returns a duration-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. This is the safe variant of getDuration(String).

        Durations can be of the form "{number}{unit}", where unit is one of:

        • ms
        • s
        • m
        • h
        • d

        If no unit is specified, milliseconds is the assumed duration unit.

      • getList

        @Deprecated
        public List<String> getList​(String name)
        Deprecated.
        Use the getList(String, List) variant instead.
        Returns a list-valued configuration property or an empty list if a property with name name has not been configured. The format of the original value must be comma-separated, e.g. one,two,three.
      • getList

        public List<String> getList​(String name,
                                    List<String> defaultValue)
        Returns a list-valued configuration property or defaultValue if a property with name name has not been configured. The format of the original value must be comma-separated, e.g. one,two,three.
      • getMap

        @Deprecated
        public Map<String,​String> getMap​(String name)
        Deprecated.
        Use the getMap(String, Map) variant instead.
        Returns a map-valued configuration property or an empty map if a property with name name has not been configured. The format of the original value must be comma-separated for each key, with an '=' separating the key and value, e.g. key=value,anotherKey=anotherValue.
        Throws:
        ConfigParsingException - if the property is not a valid long.
      • getMap

        public Map<String,​String> getMap​(String name,
                                               Map<String,​String> defaultValue)
        Returns a map-valued configuration property or defaultValue if a property with name name has not been configured or when parsing has failed. This is the safe variant of getMap(String). The format of the original value must be comma-separated for each key, with an '=' separating the key and value, e.g. key=value,anotherKey=anotherValue.
      • isInstrumentationEnabled

        public boolean isInstrumentationEnabled​(Iterable<String> instrumentationNames,
                                                boolean defaultEnabled)
      • isInstrumentationPropertyEnabled

        public boolean isInstrumentationPropertyEnabled​(Iterable<String> instrumentationNames,
                                                        String suffix,
                                                        boolean defaultEnabled)
      • isAgentDebugEnabled

        public boolean isAgentDebugEnabled()