We use the class only for ASTs. Caching them is good for periods of
parsing churn, such as startup, but the items should expire after not
being used for some time.
Change-Id: I38d95b62fd823906b851466c39429aaab7a72b56
Signed-off-by: Robert Varga <rovarga@cisco.com>
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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;
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());
}
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);
@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.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;
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);
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();
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);
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) {
}
public static YangTextSchemaContextResolver create(final String name) {