Class ConfigFragment
- All Implemented Interfaces:
FragmentDataAccess
- Direct Known Subclasses:
BackoffPolicyFragment,CommonConfigFragment
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final FragmentDataAccessThe data access object for this fragment. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConfigFragment(FragmentDataAccess dataAccess) Construct the ConfigFragment. -
Method Summary
Modifier and TypeMethodDescriptiongetBoolean(String key) Get the boolean value associated with the key.<T> TgetConfiguredInstance(String key, Class<? extends T> clazz) Creates a configured instance of the class specified by the key.final IntegerGet the integer value associated with the key.Get the list of strings associated with the key.final LongGet the long value associated with the key.org.apache.kafka.common.config.types.PasswordgetPassword(String key) Get the password associated with the key.final StringGets the String value from the key.final booleanDetermines if a key has been set.static voidlogDeprecated(org.slf4j.Logger logger, String old) Logs a deprecated message for a deprecated configuration key.static voidlogDeprecated(org.slf4j.Logger logger, String old, String replacement) Logs a deprecated message for a deprecated configuration key.static voidlogDeprecated(org.slf4j.Logger logger, String old, String formatStr, Object... args) Logs a deprecated message for a deprecated configuration key.protected voidregisterIssue(Map<String, org.apache.kafka.common.config.ConfigValue> configMap, String name, Object value, String message) Registers an issue in the Config map.voidvalidate()Deprecated.voidValidate that the data in the configuration matches any restrictions other than those from the validator.protected static StringvalidationMessage(String name, Object value, String message) Create a validation message.values()Gets the map of String to value.
-
Field Details
-
dataAccess
The data access object for this fragment.
-
-
Constructor Details
-
ConfigFragment
Construct the ConfigFragment.- Parameters:
dataAccess- the FragmentDataAccess that this fragment is associated with.
-
-
Method Details
-
validationMessage
Create a validation message.- Parameters:
name- the name of the configuration property.value- the value associated with that property.message- additional info May benull.- 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
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 toString.format(java.lang.String, java.lang.Object...)the args.args- the arguments to format with theformatStr
-
logDeprecated
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
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.Validate that the data in the configuration matches any restrictions. Default implementation does nothing. -
values
Description copied from interface:FragmentDataAccessGets the map of String to value.- Specified by:
valuesin interfaceFragmentDataAccess- Returns:
- the map of String to value.
-
getString
Description copied from interface:FragmentDataAccessGets the String value from the key.- Specified by:
getStringin interfaceFragmentDataAccess- Parameters:
key- the key to lookup.- Returns:
- the String value associated with the key.
-
has
Description copied from interface:FragmentDataAccessDetermines if a key has been set.- Specified by:
hasin interfaceFragmentDataAccess- Parameters:
key- The key to check.- Returns:
trueif the key was set,falseif the key was not set or does not exist in the config.
-
getInt
Description copied from interface:FragmentDataAccessGet the integer value associated with the key.- Specified by:
getIntin interfaceFragmentDataAccess- Parameters:
key- the key to look up.- Returns:
- the integer value.
-
getLong
Description copied from interface:FragmentDataAccessGet the long value associated with the key.- Specified by:
getLongin interfaceFragmentDataAccess- Parameters:
key- the key to look up.- Returns:
- the long value.
-
getBoolean
Description copied from interface:FragmentDataAccessGet the boolean value associated with the key.- Specified by:
getBooleanin interfaceFragmentDataAccess- Parameters:
key- the key to look up.- Returns:
- the boolean value.
-
getList
Description copied from interface:FragmentDataAccessGet the list of strings associated with the key.- Specified by:
getListin interfaceFragmentDataAccess- Parameters:
key- the key to look up.- Returns:
- the list of strings.
-
getPassword
Description copied from interface:FragmentDataAccessGet the password associated with the key.- Specified by:
getPasswordin interfaceFragmentDataAccess- Parameters:
key- the key to look up.- Returns:
- the password associated with the key.
-
getConfiguredInstance
Description copied from interface:FragmentDataAccessCreates 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:
getConfiguredInstancein interfaceFragmentDataAccess- 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.
-