Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

In this page you can find the example usage for java.util Properties getProperty.

Prototype

public String getProperty(String key, String defaultValue) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:gobblin.kafka.schemareg.KafkaSchemaRegistryFactory.java

@SuppressWarnings("unchecked")
public static KafkaSchemaRegistry getSchemaRegistry(Properties props) {
    Preconditions.checkArgument(//ww w .  ja  va  2 s.c  o m
            props.containsKey(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS),
            "Missing required property " + KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS);

    boolean tryCache = Boolean.parseBoolean(props.getProperty(
            KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CACHE, DEFAULT_TRY_CACHING));

    Class<?> clazz;
    try {
        clazz = (Class<?>) Class
                .forName(props.getProperty(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_CLASS));
        KafkaSchemaRegistry schemaRegistry = (KafkaSchemaRegistry) ConstructorUtils.invokeConstructor(clazz,
                props);
        if (tryCache && !schemaRegistry.hasInternalCache()) {
            schemaRegistry = new CachingKafkaSchemaRegistry(schemaRegistry);
        }
        return schemaRegistry;
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException
            | InstantiationException e) {
        log.error("Failed to instantiate " + KafkaSchemaRegistry.class, e);
        throw Throwables.propagate(e);
    }
}