public final class JsonValidatorCache extends Object
This class plays a critically important role in the performance of the whole validation process, since it is the class responsible for instantiating validators and caching them for future reuse.
As it uses a LoadingCache, it is totally thread safe and also
very efficient.
Another critically important class for speed is SchemaNode, since
the cache uses them as keys.
SchemaNode| Modifier and Type | Class and Description |
|---|---|
private static class |
JsonValidatorCache.FailingValidator
Class instantiated when a schema node fails to pass ref resolution or
syntax checking
|
| Modifier and Type | Field and Description |
|---|---|
private LoadingCache<SchemaNode,JsonValidator> |
cache |
private KeywordFactory |
keywordFactory |
private JsonResolver |
resolver |
private SyntaxValidator |
syntaxValidator |
| Constructor and Description |
|---|
JsonValidatorCache(KeywordBundle bundle,
SchemaRegistry registry)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
private CacheLoader<SchemaNode,JsonValidator> |
cacheLoader()
The cache loader function
|
JsonValidator |
getValidator(SchemaNode schemaNode) |
private final LoadingCache<SchemaNode,JsonValidator> cache
private final JsonResolver resolver
private final SyntaxValidator syntaxValidator
private final KeywordFactory keywordFactory
public JsonValidatorCache(KeywordBundle bundle, SchemaRegistry registry)
Instantiate the syntax validator, the keyword factory, the JSON ref resolver and the validator cache.
bundle - registry - public JsonValidator getValidator(SchemaNode schemaNode)
private CacheLoader<SchemaNode,JsonValidator> cacheLoader()
The implemented CacheLoader.load(Object) method is the
critical part. It will try and check if ref resolution succeeds, if so it
checks the schema syntax, and finally it returns a validator.
If any of the preliminary checks fail, it returns a JsonValidatorCache.FailingValidator, else it returns an InstanceValidator.
Copyright © 2012. All Rights Reserved.