Java Code Examples for org.apache.kafka.common.config.ConfigDef#Validator
The following examples show how to use
org.apache.kafka.common.config.ConfigDef#Validator .
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: KafkaConfigProxyFactory.java From kafka-connect-couchbase with Apache License 2.0 | 6 votes |
protected ConfigDef.Validator getDefaultValidator(Method method) { CustomTypeHandler<?> customTypeHandler = customTypeMap.get(method.getReturnType()); if (customTypeHandler != null) { ConfigDef.Validator v = customTypeHandler.validator(); if (v != null) { return v; } } if (method.getReturnType().isEnum()) { //noinspection unchecked return new EnumValidator((Class<? extends Enum<?>>) method.getReturnType()); } return null; }
Example 2
Source File: ConfigHelper.java From kafka-connect-couchbase with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public static <T> ConfigDef.Validator validate(SimpleValidator<T> validator, String description) { return new ConfigDef.Validator() { @Override public String toString() { return description; } @Override public void ensureValid(String name, Object value) { try { validator.validate((T) value); } catch (Exception e) { throw new ConfigException(name, value, e.getMessage()); } } }; }
Example 3
Source File: ValidClassTest.java From MongoDb-Sink-Connector with Apache License 2.0 | 5 votes |
@Test public void ensureValid() throws Exception { ConfigDef.Validator validator = ValidClass.isSubclassOf(A.class); // same class validator.ensureValid("myname", A.class); // anonymous subclass validator.ensureValid("myname", B.class); }
Example 4
Source File: KafkaConfigProxyFactory.java From kafka-connect-couchbase with Apache License 2.0 | 5 votes |
protected ConfigDef.Validator getValidator(Method method) { ConfigDef.Validator userProvided = (ConfigDef.Validator) invokeCompanion(method, "Validator"); if (userProvided != null) { return userProvided; } return getDefaultValidator(method); }
Example 5
Source File: KafkaConfigProxyFactoryTest.java From kafka-connect-couchbase with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") static ConfigDef.Validator stringValueValidator() { return (name, value) -> { if (((String) value).contains("z")) { throw new ConfigException(name, value, "The letter 'z' has been outlawed."); } }; }
Example 6
Source File: KafkaConfigModelGenerator.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private static List<String> enumer(ConfigDef.Validator validator) { try { Field f = getField(ConfigDef.ValidString.class, "validStrings"); return (List) f.get(validator); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } }
Example 7
Source File: Validators.java From mongo-kafka with Apache License 2.0 | 5 votes |
public static ValidatorWithOperators withStringDef( final String validatorString, final ConfigDef.Validator validator) { return new ValidatorWithOperators() { @Override public void ensureValid(final String name, final Object value) { validator.ensureValid(name, value); } @Override public String toString() { return validatorString; } }; }
Example 8
Source File: ValidCharsetTest.java From connect-utils with Apache License 2.0 | 5 votes |
@Test public void display() { ConfigDef.Validator validator = new ValidCharset("UTF-8"); final String expected = "Valid values: 'UTF-8'"; final String actual = validator.toString(); System.out.println(actual); assertEquals(expected, actual); }
Example 9
Source File: MongoDbSinkConnectorConfig.java From kafka-connect-mongodb with Apache License 2.0 | 5 votes |
default ValidatorWithOperators or(ConfigDef.Validator other) { return (name, value) -> { try { this.ensureValid(name, value); } catch (ConfigException e) { other.ensureValid(name, value); } }; }
Example 10
Source File: ValidCharsetTest.java From connect-utils with Apache License 2.0 | 4 votes |
@Test public void list() { ConfigDef.Validator validator = new ValidCharset(); validator.ensureValid("testing", Arrays.asList("UTF-8", "UTF-16")); System.out.println(validator); }
Example 11
Source File: ValidCharsetTest.java From connect-utils with Apache License 2.0 | 4 votes |
@Test public void utf8() { ConfigDef.Validator validator = new ValidCharset(); validator.ensureValid("testing", "utf8"); }
Example 12
Source File: BlankOrValidator.java From connect-utils with Apache License 2.0 | 4 votes |
public static ConfigDef.Validator of(ConfigDef.Validator validator) { return new BlankOrValidator(validator); }
Example 13
Source File: ValidClassTest.java From MongoDb-Sink-Connector with Apache License 2.0 | 4 votes |
@Test(expected = ConfigException.class) public void ensureValidNotSubclass() { ConfigDef.Validator validator = ValidClass.isSubclassOf(A.class); validator.ensureValid("myname", C.class); }
Example 14
Source File: BlankOrValidator.java From connect-utils with Apache License 2.0 | 4 votes |
BlankOrValidator(ConfigDef.Validator validator) { Preconditions.checkNotNull(validator, "validator cannot be null."); this.validator = validator; }
Example 15
Source File: ValidClassTest.java From MongoDb-Sink-Connector with Apache License 2.0 | 4 votes |
@Test(expected = ConfigException.class) public void ensureValidNotAccessible() { // not instantiable ConfigDef.Validator validator = ValidClass.isSubclassOf(A.class); validator.ensureValid("myname", E.class); }
Example 16
Source File: ConfigKeyBuilder.java From connect-utils with Apache License 2.0 | 4 votes |
public ConfigDef.Validator validator() { return this.validator; }
Example 17
Source File: SinkBehaviorConfig.java From kafka-connect-couchbase with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") static ConfigDef.Validator defaultCollectionValidator() { return validate(ScopeAndCollection::parse, "A collection name qualified by a scope name (scope.collection)"); }
Example 18
Source File: SinkBehaviorConfig.java From kafka-connect-couchbase with Apache License 2.0 | 4 votes |
@SuppressWarnings("unused") static ConfigDef.Validator topicToCollectionValidator() { return validate(TopicMap::parse, "topic=scope.collection,..."); }
Example 19
Source File: Plugin.java From connect-utils with Apache License 2.0 | 4 votes |
@Nullable ConfigDef.Validator getValidator();
Example 20
Source File: MongoDbSinkConnectorConfig.java From kafka-connect-mongodb with Apache License 2.0 | 4 votes |
default ValidatorWithOperators and(ConfigDef.Validator other) { return (name, value) -> { this.ensureValid(name, value); other.ensureValid(name, value); }; }