java.lang.Object
io.aiven.commons.kafka.config.fragment.ConfigFragment
All Implemented Interfaces:
FragmentDataAccess
Direct Known Subclasses:
BackoffPolicyFragment, CommonConfigFragment

public class ConfigFragment extends Object implements FragmentDataAccess
Config fragments encapsulate logical fragments of configuration that may be used across multiple Connectors or across the source/sink of a connector pair.

All implementing classes should be final. All configuration keys should be specified as static final String within the fragment. They should be package private so that test code can use them. All implementing classes must implement a public static ConfigDef update(final ConfigDef configDef) method, though more arguments are allowed. The method must add the definitions for the configuration options the fragment supports to the configDef parameter and return it. Access to the configuration within the fragment is via the dataAccess property. All access to configuration values should be through methods. For example if the string value of the "foo" config options should be returned then the method { @code public String getFoo() } should be created. All complex access to configuration values should be encapsulated within methods. For example if the Baz object requires the "foo" and "bar" values then something like public Baz getBaz() { return new Baz(getFoo(), cfg.getString("bar")); } should be created. Any fragment depends on another fragment may create it inline and use it. The validate(Map) method may call the validate methods on the dependant fragments during validation.

  • Field Details

    • dataAccess

      protected final FragmentDataAccess dataAccess
      The data access object for this fragment.
  • Constructor Details

    • ConfigFragment

      protected ConfigFragment(FragmentDataAccess dataAccess)
      Construct the ConfigFragment.
      Parameters:
      dataAccess - the FragmentDataAccess that this fragment is associated with.
  • Method Details

    • validationMessage

      protected static String validationMessage(String name, Object value, String message)
      Create a validation message.
      Parameters:
      name - the name of the configuration property.
      value - the value associated with that property.
      message - additional info May be null.
      Returns:
      A formatted validatio nmessage.
    • registerIssue

      protected void registerIssue(Map<String,org.apache.kafka.common.config.ConfigValue> configMap, String name, Object value, String message)
      Registers an issue in the Config map.
      Parameters:
      configMap - The map of name to ConfigValue.
      name - the name of the item with the error.
      value - the value of the item.
      message - the message for the error.
    • logDeprecated

      public static void logDeprecated(org.slf4j.Logger logger, String old, String replacement)
      Logs a deprecated message for a deprecated configuration key.
      Parameters:
      logger - the logger to log to.
      old - the deprecated configuration key.
      replacement - the replacement configuration key.
    • logDeprecated

      public static void logDeprecated(org.slf4j.Logger logger, String old, String formatStr, Object... args)
      Logs a deprecated message for a deprecated configuration key. This method should only be used when the key does not have a replacement and the documentation describes what to do.
      Parameters:
      logger - the logger to log to.
      old - the deprecated configuration key.
      formatStr - the string to String.format(java.lang.String, java.lang.Object...) the args.
      args - the arguments to format with the formatStr
    • logDeprecated

      public static void logDeprecated(org.slf4j.Logger logger, String old)
      Logs a deprecated message for a deprecated configuration key. This method should only be used when the key does not have a replacement and the documentation describes what to do.
      Parameters:
      logger - the logger to log to.
      old - the deprecated configuration key.
    • validate

      public void validate(Map<String,org.apache.kafka.common.config.ConfigValue> configMap)
      Validate that the data in the configuration matches any restrictions other than those from the validator. Default implementation does nothing.
      Parameters:
      configMap - The map of ConfigValues that have issues
    • validate

      @Deprecated public void validate()
      Deprecated.
      Validate that the data in the configuration matches any restrictions. Default implementation does nothing.
    • values

      public final Map<String,?> values()
      Description copied from interface: FragmentDataAccess
      Gets the map of String to value.
      Specified by:
      values in interface FragmentDataAccess
      Returns:
      the map of String to value.
    • getString

      public final String getString(String key)
      Description copied from interface: FragmentDataAccess
      Gets the String value from the key.
      Specified by:
      getString in interface FragmentDataAccess
      Parameters:
      key - the key to lookup.
      Returns:
      the String value associated with the key.
    • has

      public final boolean has(String key)
      Description copied from interface: FragmentDataAccess
      Determines if a key has been set.
      Specified by:
      has in interface FragmentDataAccess
      Parameters:
      key - The key to check.
      Returns:
      true if the key was set, false if the key was not set or does not exist in the config.
    • getInt

      public final Integer getInt(String key)
      Description copied from interface: FragmentDataAccess
      Get the integer value associated with the key.
      Specified by:
      getInt in interface FragmentDataAccess
      Parameters:
      key - the key to look up.
      Returns:
      the integer value.
    • getLong

      public final Long getLong(String key)
      Description copied from interface: FragmentDataAccess
      Get the long value associated with the key.
      Specified by:
      getLong in interface FragmentDataAccess
      Parameters:
      key - the key to look up.
      Returns:
      the long value.
    • getBoolean

      public Boolean getBoolean(String key)
      Description copied from interface: FragmentDataAccess
      Get the boolean value associated with the key.
      Specified by:
      getBoolean in interface FragmentDataAccess
      Parameters:
      key - the key to look up.
      Returns:
      the boolean value.
    • getList

      public List<String> getList(String key)
      Description copied from interface: FragmentDataAccess
      Get the list of strings associated with the key.
      Specified by:
      getList in interface FragmentDataAccess
      Parameters:
      key - the key to look up.
      Returns:
      the list of strings.
    • getPassword

      public org.apache.kafka.common.config.types.Password getPassword(String key)
      Description copied from interface: FragmentDataAccess
      Get the password associated with the key.
      Specified by:
      getPassword in interface FragmentDataAccess
      Parameters:
      key - the key to look up.
      Returns:
      the password associated with the key.
    • getConfiguredInstance

      public <T> T getConfiguredInstance(String key, Class<? extends T> clazz)
      Description copied from interface: FragmentDataAccess
      Creates a configured instance of the class specified by the key. The value of the key may be either a class name or the instance of the class itsef.
      Specified by:
      getConfiguredInstance in interface FragmentDataAccess
      Type Parameters:
      T - the expected type of the return value.
      Parameters:
      key - the key to look up.
      clazz - class to return.
      Returns:
      an object of class clazz.