@Override protected void doInit(Map<String, ?> config) { schemaCache = CacheBuilder.newBuilder() .maximumSize(getCacheMaxSize(config)) .expireAfterAccess(getCacheExpiryInSecs(config), TimeUnit.SECONDS) .build(new CacheLoader<SchemaVersionKey, S>() { @Override public S load(SchemaVersionKey schemaVersionKey) { try { return getParsedSchema(schemaVersionKey); } catch (SchemaNotFoundException | InvalidSchemaException e) { throw new RegistryException(e); } } }); }
private Integer getCacheMaxSize(Map<String, ?> config) { Integer value = (Integer) getValue(config, DESERIALIZER_SCHEMA_CACHE_MAX_SIZE, DEFAULT_SCHEMA_CACHE_SIZE); if (value < 0) { throw new IllegalArgumentException("Property: " + DESERIALIZER_SCHEMA_CACHE_MAX_SIZE + " must be non negative."); } return value; }
@Override public O deserialize(I input, Integer readerSchemaVersion) throws SerDesException { ensureInitialized(); // it can be enhanced to have respective protocol handlers for different versions byte protocolId = retrieveProtocolId(input); SchemaIdVersion schemaIdVersion = retrieveSchemaIdVersion(protocolId, input); SchemaVersionInfo schemaVersionInfo; SchemaMetadata schemaMetadata; try { schemaVersionInfo = schemaRegistryClient.getSchemaVersionInfo(schemaIdVersion); schemaMetadata = schemaRegistryClient.getSchemaMetadataInfo(schemaVersionInfo.getName()).getSchemaMetadata(); } catch (Exception e) { throw new RegistryException(e); } return doDeserialize(input, protocolId, schemaMetadata, schemaVersionInfo.getVersion(), readerSchemaVersion); }
@Override public S load(SchemaVersionKey schemaVersionKey) { try { return getParsedSchema(schemaVersionKey); } catch (SchemaNotFoundException | InvalidSchemaException e) { throw new RegistryException(e); } } });
@Override public void doInit(Map<String, ?> config) { super.doInit(config); SchemaVersionRetriever schemaVersionRetriever = createSchemaVersionRetriever(); avroSchemaResolver = new AvroSchemaResolver(schemaVersionRetriever); useSpecificAvroReader = (boolean) getValue(config, SPECIFIC_AVRO_READER, false); }
private Long getCacheExpiryInSecs(Map<String, ?> config) { Long value = (Long) getValue(config, DESERIALIZER_SCHEMA_CACHE_EXPIRY_IN_SECS, DEFAULT_DESERIALIZER_SCHEMA_CACHE_EXPIRY_IN_SECS); if (value < 0) { throw new IllegalArgumentException("Property: " + DESERIALIZER_SCHEMA_CACHE_EXPIRY_IN_SECS + " must be non negative."); } return value; }