コード例 #1
0
 protected CacheSchemaLibrary schemaLibrary(boolean createIfMissing) {
   CacheSchemaLibrary schemaLibrary = this.schemaLibrary.get();
   if (schemaLibrary == null && createIfMissing) {
     // Now get the cache for the schema and create the library ...
     Cache<String, SchematicEntry> schemaStore =
         this.store.getCacheManager().getCache(schemaCacheName);
     schemaLibrary = new CacheSchemaLibrary(schemaStore);
     if (this.schemaLibrary.compareAndSet(null, schemaLibrary)) {
       schemaLibrary.start();
     } else {
       // Someone else snuck in and set the value ...
       schemaLibrary = this.schemaLibrary.get();
     }
   }
   return schemaLibrary;
 }
コード例 #2
0
  @Override
  public Map<String, Results> validateAll() {
    CacheSchemaLibrary schemaLibrary = schemaLibrary(true);
    if (store.getAdvancedCache().getRpcManager() == null) {
      // This is a non-clustered cache, which cannot run Map-Reduce. In this case, just go through
      // them
      // all and run validation manually using the mapper...
      DocumentValidationMapper mapper =
          new DocumentValidationMapper(schemaLibrary, defaultSchemaUri);
      ResultsCollector resultsCollector = new ResultsCollector();
      for (Map.Entry<String, SchematicEntry> entry : store.entrySet()) {
        String key = entry.getKey();
        SchematicEntry value = entry.getValue();
        mapper.map(key, value, resultsCollector);
      }
      return resultsCollector.getResultsByKey();
    }

    // It is a clustered cache, so we can run Map-Reduce ...

    // Create a copy of all of the JSON Schema documents ...
    InMemoryDocumentLibrary schemaDocs = new InMemoryDocumentLibrary(schemaLibrary.getName());
    for (Map.Entry<String, SchematicEntry> entry : schemaLibrary.store().entrySet()) {
      String key = entry.getKey();
      SchematicEntry value = entry.getValue();
      schemaDocs.put(key, value.getContentAsDocument());
    }

    // Now create the Map-Reduce task, using the copy of the JSON Schema library ...
    MapReduceTask<String, SchematicEntry, String, Results> task =
        new MapReduceTask<String, SchematicEntry, String, Results>(this.store);
    task.mappedWith(new DocumentValidationMapper(schemaDocs, defaultSchemaUri));
    task.reducedWith(new DocumentValidationReducer());

    // Now execute ...
    return task.execute();
  }
コード例 #3
0
 @Override
 public void stop() {
   this.store.stop();
   CacheSchemaLibrary schemaLibrary = schemaLibrary(false);
   if (schemaLibrary != null) schemaLibrary.stop();
 }