org.schemarepo
Class AbstractBackendRepository

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

public abstract class AbstractBackendRepository
extends BaseRepository

Parent class of the actual backend (as opposed to decorating) repositories. Each backend repository is expected to cache and validate its subjects.


Field Summary
protected  InMemorySubjectCache subjectCache
           
protected  ValidatorFactory validators
           
 
Fields inherited from class org.schemarepo.BaseRepository
closed, logger
 
Constructor Summary
protected AbstractBackendRepository(ValidatorFactory validators)
           
 
Method Summary
protected  Subject cacheSubject(Subject subject)
          Applies validation decorator, and caches subject.
protected  boolean checkSubjectExistsInBackend(String subjectName)
          Backend-specific check if the subject actually exists.
protected  Subject getAndCacheSubject(String subjectName)
          Creates, applies validation decorator, and caches subject.
protected abstract  Subject getSubjectInstance(String subjectName)
          Concrete subclasses must override to return specific implementation of Subject.
 Subject lookup(String subjectName)
          Returns the subject if it exists, null otherwise.
 Subject register(String subjectName, SubjectConfig config)
          Attempt to create a Subject with the given name and validator.
protected abstract  void registerSubjectInBackend(String subjectName, SubjectConfig config)
          Backend-specific registration logic.
 Iterable<Subject> subjects()
          List all subjects.
 
Methods inherited from class org.schemarepo.BaseRepository
close, exposeConfiguration, isValid, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

subjectCache

protected final InMemorySubjectCache subjectCache

validators

protected final ValidatorFactory validators
Constructor Detail

AbstractBackendRepository

protected AbstractBackendRepository(ValidatorFactory validators)
Method Detail

getSubjectInstance

protected abstract Subject getSubjectInstance(String subjectName)
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 registerSubjectInBackend(String, SubjectConfig)

Parameters:
subjectName - subject name
Returns:
Subject

getAndCacheSubject

protected final Subject getAndCacheSubject(String subjectName)
Creates, applies validation decorator, and caches subject.

Parameters:
subjectName - subject name
Returns:
Subject the newly created instance or possibly pre-existing cached instance

cacheSubject

protected final Subject cacheSubject(Subject subject)
Applies validation decorator, and caches subject.

Parameters:
subject - subject to cache
Returns:
Subject the passed instance or possibly pre-existing cached instance

register

public Subject register(String subjectName,
                        SubjectConfig config)
Description copied from interface: Repository
Attempt to create a Subject with the given name and validator.

Parameters:
subjectName - The name of the subject. Must not be null.
config - The subject configuration. May be null.
Returns:
The newly created Subject, or an equivalent one if already created. Does not return null.

registerSubjectInBackend

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

Parameters:
subjectName - subject name
config - subject config

lookup

public Subject lookup(String subjectName)
Description copied from interface: Repository
Returns the subject if it exists, null otherwise.

Parameters:
subjectName - the subject name
Returns:
The subject if it exists, null otherwise.

checkSubjectExistsInBackend

protected boolean checkSubjectExistsInBackend(String subjectName)
Backend-specific check if the subject actually exists. This is called during lookup upon cache miss. Usually is overridden by subclasses. By default, assume that a subject does not exist if it's not in cache.

Parameters:
subjectName - subject name
Returns:
boolean

subjects

public Iterable<Subject> subjects()
Description copied from interface: Repository
List all subjects. Does not return null.



Copyright © 2015. All rights reserved.