Java Code Examples for org.apache.kafka.common.config.AbstractConfig#getList()
The following examples show how to use
org.apache.kafka.common.config.AbstractConfig#getList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 6 votes |
/** * Method is used to return enums from a list. * * @param enumClass * @param config * @param key * @param <T> * @return * @see com.github.jcustenborder.kafka.connect.utils.config.validators.Validators#validEnum(Class, Enum[]) */ public static <T extends Enum<T>> List<T> getEnums(Class<T> enumClass, AbstractConfig config, String key) { Preconditions.checkNotNull(enumClass, "enumClass cannot be null"); Preconditions.checkState(enumClass.isEnum(), "enumClass must be an enum."); Preconditions.checkState( ConfigDef.Type.LIST == config.typeOf(key), "'%s' must be a list", key ); List<T> result = new ArrayList<>(); List<String> values = config.getList(key); for (String value : values) { result.add(Enum.valueOf(enumClass, value)); } return result; }
Example 2
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 6 votes |
/** * Method is used to return a charset(s) for a list key. * * @param config Config to read from. * @param key Key to read from * @return */ public static List<Charset> charsets(AbstractConfig config, String key) { final List<String> charsetNames = config.getList(key); final List<Charset> result = new ArrayList<>(charsetNames.size()); for (String charsetName : charsetNames) { try { Charset charset = Charset.forName(charsetName); result.add(charset); } catch (final UnsupportedCharsetException ex) { ConfigException exception = new ConfigException(key, charsetName, "Invalid charset."); exception.initCause(ex); throw exception; } } return result; }
Example 3
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 5 votes |
/** * Method is used to return a list of InetSocketAddress from a config list of hostname:port strings. * * @param config config to read the value from * @param key key for the value * @return List of InetSocketAddress for the supplied strings. */ public static List<InetSocketAddress> inetSocketAddresses(AbstractConfig config, String key) { Preconditions.checkNotNull(config, "config cannot be null"); List<String> value = config.getList(key); List<InetSocketAddress> addresses = new ArrayList<>(value.size()); for (String s : value) { addresses.add(parseInetSocketAddress(s)); } return ImmutableList.copyOf(addresses); }
Example 4
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 5 votes |
/** * Method is used to parse a list ConfigDef item to a list of HostAndPort * * @param config Config to read from * @param key ConfigItem to get the host string from. * @param defaultPort The default port to use if a port was not specified. Can be null. * @return */ public static List<HostAndPort> hostAndPorts(AbstractConfig config, String key, Integer defaultPort) { final List<String> inputs = config.getList(key); List<HostAndPort> result = new ArrayList<>(); for (final String input : inputs) { final HostAndPort hostAndPort = hostAndPort(input, defaultPort); result.add(hostAndPort); } return ImmutableList.copyOf(result); }
Example 5
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 5 votes |
/** * Method is used to retrieve a list of URL(s) from a configuration key. * * @param config Config to read * @param key Key to read * @return URL for the value. */ public static List<URL> urls(AbstractConfig config, String key) { List<URL> result = new ArrayList<>(); List<String> input = config.getList(key); for (String s : input) { result.add(url(key, s)); } return ImmutableList.copyOf(result); }
Example 6
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 5 votes |
/** * Method is used to retrieve a list of URI(s) from a configuration key. * * @param config Config to read * @param key Key to read * @return URI for the value. */ public static List<URI> uris(AbstractConfig config, String key) { List<URI> result = new ArrayList<>(); List<String> input = config.getList(key); for (String s : input) { result.add(uri(key, s)); } return ImmutableList.copyOf(result); }
Example 7
Source File: ConfigUtils.java From connect-utils with Apache License 2.0 | 2 votes |
/** * Method is used to retrieve a list and convert it to an immutable set. * * @param config Config to read * @param key Key to read * @return ImmutableSet with the contents of the config key. * @see com.google.common.collect.ImmutableSet */ public static Set<String> getSet(AbstractConfig config, String key) { List<String> value = config.getList(key); return ImmutableSet.copyOf(value); }