org.schemarepo
Class LocalFileSystemRepository

java.lang.Object
  extended by org.schemarepo.BaseRepository
      extended by org.schemarepo.AbstractBackendRepository
          extended by org.schemarepo.LocalFileSystemRepository
All Implemented Interfaces:
Closeable, Repository

public class LocalFileSystemRepository
extends AbstractBackendRepository

A Repository that persists content to file.

The Repository stores all of its data in a single base directory. Within this directory each Subject is represented by a nested directory with the same name as the Subject. Within each Subject directory there are three file types:

  • A properties file named 'subject.properties' containing the configured properties for the Subject. At this time, the only used property is "schema-repo.validator.class".
  • A text file named 'schema_ids' containing the schema ids, in order of their creation, delimited by newline, encoded in UTF-8. This is used to track the order of schema registration for Subject.latest() and Subject.allEntries()
  • One file per schema the contents of which are the schema encoded in UTF-8 and the name of which is the schema id followed by the postfix '.schema'.

  • Field Summary
     
    Fields inherited from class org.schemarepo.AbstractBackendRepository
    subjectCache, validators
     
    Fields inherited from class org.schemarepo.BaseRepository
    closed
     
    Constructor Summary
    LocalFileSystemRepository(String repoPath, ValidatorFactory validators)
              Create a LocalFileSystemRepository in the directory path provided.
     
    Method Summary
     void close()
               
    protected  Map<String,String> exposeConfiguration()
              Expose certain configuration elements as properties.
    protected  Subject getSubjectInstance(String subjectName)
              Concrete subclasses must override to return specific implementation of Subject.
    protected  void registerSubjectInBackend(String subjectName, SubjectConfig config)
              Backend-specific registration logic.
     
    Methods inherited from class org.schemarepo.AbstractBackendRepository
    cacheSubject, checkSubjectExistsInBackend, getAndCacheSubject, lookup, register, subjects
     
    Methods inherited from class org.schemarepo.BaseRepository
    isValid, toString
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    LocalFileSystemRepository

    @Inject
    public LocalFileSystemRepository(@Named(value="schema-repo.local-file-system.path")
                                            String repoPath,
                                            ValidatorFactory validators)
    Create a LocalFileSystemRepository in the directory path provided. Locks a file "repository.lock" to ensure no other object or process is running a LocalFileSystemRepository from the same place. The lock is released if close() is called, the object is finalized, or the JVM exits. Not all platforms support file locks. See FileLock

    Parameters:
    repoPath - The path where to store the Repository's state
    Method Detail

    close

    public void close()
    Specified by:
    close in interface Closeable
    Overrides:
    close in class BaseRepository

    getSubjectInstance

    protected Subject getSubjectInstance(String subjectName)
    Description copied from class: AbstractBackendRepository
    Concrete subclasses must override to return specific implementation of Subject. Note that this instantiates the "right" subject only, any "side effects" (such as mutating persistent state) must be implemented in AbstractBackendRepository.registerSubjectInBackend(String, SubjectConfig)

    Specified by:
    getSubjectInstance in class AbstractBackendRepository
    Parameters:
    subjectName - subject name
    Returns:
    Subject

    registerSubjectInBackend

    protected void registerSubjectInBackend(String subjectName,
                                            SubjectConfig config)
    Description copied from class: AbstractBackendRepository
    Backend-specific registration logic. This is called during registration upon cache miss. Responsible for the persistent "side effects".

    Specified by:
    registerSubjectInBackend in class AbstractBackendRepository
    Parameters:
    subjectName - subject name
    config - subject config

    exposeConfiguration

    protected Map<String,String> exposeConfiguration()
    Description copied from class: BaseRepository
    Expose certain configuration elements as properties. This can be used to construct a useful toString() response, for ex.

    Remember to call

    super
    when overriding!

    Overrides:
    exposeConfiguration in class BaseRepository
    Returns:
    Map representing properties; note that the actual implementation may be immutable


    Copyright © 2015. All rights reserved.