import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.TimeUnit;
import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues());
}
+ public static <R extends SchemaSourceRepresentation> InMemorySchemaSourceCache<R> createSoftCache(
+ final SchemaSourceRegistry consumer, final Class<R> representation, final long lifetime, final TimeUnit units) {
+ return new InMemorySchemaSourceCache<>(consumer, representation, CacheBuilder.newBuilder().softValues()
+ .expireAfterAccess(lifetime, units));
+ }
+
@Override
public CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
final T present = cache.getIfPresent(sourceIdentifier);
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public final class YangTextSchemaContextResolver implements AutoCloseable, SchemaSourceProvider<YangTextSchemaSource> {
private static final Logger LOG = LoggerFactory.getLogger(YangTextSchemaContextResolver.class);
+ private static final long SOURCE_LIFETIME_SECONDS = 60;
private final Collection<SourceIdentifier> requiredSources = new ConcurrentLinkedDeque<>();
private final Multimap<SourceIdentifier, YangTextSchemaSource> texts = ArrayListMultimap.create();
final TextToASTTransformer t = TextToASTTransformer.create(repository, registry);
transReg = registry.registerSchemaSourceListener(t);
- cache = InMemorySchemaSourceCache.createSoftCache(registry, ASTSchemaSource.class);
+ cache = InMemorySchemaSourceCache.createSoftCache(registry, ASTSchemaSource.class, SOURCE_LIFETIME_SECONDS,
+ TimeUnit.SECONDS);
}
public static YangTextSchemaContextResolver create(final String name) {