/** * Create a caching schema registry. * @param kafkaSchemaRegistry: a schema registry that needs caching * @param maxSchemaReferences: the maximum number of unique references that can exist for a given schema. */ public CachingKafkaSchemaRegistry(KafkaSchemaRegistry kafkaSchemaRegistry, int maxSchemaReferences) { Preconditions.checkArgument(kafkaSchemaRegistry!=null, "KafkaSchemaRegistry cannot be null"); Preconditions.checkArgument(!kafkaSchemaRegistry.hasInternalCache(), "SchemaRegistry already has a cache."); _kafkaSchemaRegistry = kafkaSchemaRegistry; _namedSchemaCache = new HashMap<>(); _idBasedCache = new HashMap<>(); _maxSchemaReferences = maxSchemaReferences; }
@SuppressWarnings("unchecked") public static KafkaSchemaRegistry getSchemaRegistry(Properties props) { Preconditions.checkArgument(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); } } }
/** * Create a caching schema registry. * @param kafkaSchemaRegistry: a schema registry that needs caching * @param maxSchemaReferences: the maximum number of unique references that can exist for a given schema. */ public CachingKafkaSchemaRegistry(KafkaSchemaRegistry kafkaSchemaRegistry, int maxSchemaReferences) { Preconditions.checkArgument(kafkaSchemaRegistry!=null, "KafkaSchemaRegistry cannot be null"); Preconditions.checkArgument(!kafkaSchemaRegistry.hasInternalCache(), "SchemaRegistry already has a cache."); _kafkaSchemaRegistry = kafkaSchemaRegistry; _namedSchemaCache = new HashMap<>(); _idBasedCache = new HashMap<>(); _maxSchemaReferences = maxSchemaReferences; }
@SuppressWarnings("unchecked") public static KafkaSchemaRegistry getSchemaRegistry(Properties props) { Preconditions.checkArgument(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); } } }