All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.allegro.tech.hermes.common.schema.AvroCompiledSchemaRepositoryFactory Maven / Gradle / Ivy

The newest version!
package pl.allegro.tech.hermes.common.schema;

import java.time.Duration;
import org.apache.avro.Schema;
import pl.allegro.tech.hermes.schema.CachedCompiledSchemaRepository;
import pl.allegro.tech.hermes.schema.CompiledSchemaRepository;
import pl.allegro.tech.hermes.schema.DirectCompiledSchemaRepository;
import pl.allegro.tech.hermes.schema.RawSchemaClient;
import pl.allegro.tech.hermes.schema.SchemaCompilersFactory;

public class AvroCompiledSchemaRepositoryFactory {

  private final RawSchemaClient rawSchemaClient;
  private final int maximumSize;
  private final Duration expireAfterAccess;
  private final boolean cacheEnabled;

  public AvroCompiledSchemaRepositoryFactory(
      RawSchemaClient rawSchemaClient,
      int maximumSize,
      Duration expireAfterAccess,
      boolean cacheEnabled) {
    this.rawSchemaClient = rawSchemaClient;
    this.maximumSize = maximumSize;
    this.expireAfterAccess = expireAfterAccess;
    this.cacheEnabled = cacheEnabled;
  }

  public CompiledSchemaRepository provide() {
    CompiledSchemaRepository repository =
        new DirectCompiledSchemaRepository<>(
            rawSchemaClient, SchemaCompilersFactory.avroSchemaCompiler());

    if (cacheEnabled) {
      return new CachedCompiledSchemaRepository<>(repository, maximumSize, expireAfterAccess);
    } else {
      return repository;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy