* A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
*/
SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
- private final Iterable<Class<? extends SchemaSourceRepresentation>> Representations =
+ private final Iterable<Class<? extends SchemaSourceRepresentation>> representations =
Collections.<Class<? extends SchemaSourceRepresentation>>singletonList(SchemaSourceRepresentation.class);
+ private final ListenableFuture<Boolean> applyFuture = Futures.immediateFuture(Boolean.TRUE);
@Override
public Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
- return Representations;
+ return representations;
}
@Override
public ListenableFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) {
- return Futures.immediateFuture(Boolean.TRUE);
+ return applyFuture;
}
};
private static final Logger LOG = LoggerFactory.getLogger(FilesystemSchemaSourceCache.class);
// Init storage adapters
- private static final Map<Class<? extends SchemaSourceRepresentation>, StorageAdapter<? extends SchemaSourceRepresentation>> storageAdapters =
+ private static final Map<Class<? extends SchemaSourceRepresentation>, StorageAdapter<? extends SchemaSourceRepresentation>> STORAGE_ADAPTERS =
Collections.<Class<? extends SchemaSourceRepresentation>, StorageAdapter<? extends SchemaSourceRepresentation>> singletonMap(
YangTextSchemaSource.class, new YangTextSchemaStorageAdapter());
}
private static void checkSupportedRepresentation(final Class<? extends SchemaSourceRepresentation> representation) {
- for (final Class<? extends SchemaSourceRepresentation> supportedRepresentation : storageAdapters.keySet()) {
+ for (final Class<? extends SchemaSourceRepresentation> supportedRepresentation : STORAGE_ADAPTERS.keySet()) {
if(supportedRepresentation.isAssignableFrom(representation)) {
return;
}
}
throw new IllegalArgumentException(String.format(
- "This cache does not support representation: %s, supported representations are: %s", representation, storageAdapters.keySet()));
+ "This cache does not support representation: %s, supported representations are: %s", representation, STORAGE_ADAPTERS.keySet()));
}
private static final Pattern CACHED_FILE_PATTERN =
final File file = sourceIdToFile(sourceIdentifier, storageDirectory);
if(file.exists() && file.canRead()) {
LOG.trace("Source {} found in cache as {}", sourceIdentifier, file);
- final SchemaSourceRepresentation restored = storageAdapters.get(representation).restore(sourceIdentifier, file);
+ final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier, file);
return Futures.immediateCheckedFuture(representation.cast(restored));
}
}
private void storeSource(final File file, final T schemaRepresentation) {
- storageAdapters.get(representation).store(file, schemaRepresentation);
+ STORAGE_ADAPTERS.get(representation).store(file, schemaRepresentation);
}
private static abstract class StorageAdapter<T extends SchemaSourceRepresentation> {