<description>${project.artifactId}</description>
<dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>object-cache-api</artifactId>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>util</artifactId>
import org.opendaylight.yangtools.concepts.Identifier;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
/**
* YANG Schema source identifier
*/
@Beta
public final class SourceIdentifier implements Identifier, Immutable {
-
/**
* Default revision for sources without specified revision.
* Marks the source as oldest.
*/
public static final String NOT_PRESENT_FORMATTED_REVISION = "0000-00-00";
+ private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(SourceIdentifier.class);
private static final long serialVersionUID = 1L;
private final String revision;
private final String name;
/**
- *
* Creates new YANG Schema source identifier.
*
* @param name Name of schema
* @param formattedRevision Revision of source in format YYYY-mm-dd
*/
public SourceIdentifier(final String name, final String formattedRevision) {
- super();
this.name = Preconditions.checkNotNull(name);
this.revision = Preconditions.checkNotNull(formattedRevision);
}
this(name, formattedRevision.or(NOT_PRESENT_FORMATTED_REVISION));
}
+ /**
+ * Return a cached reference to an object equal to this object.
+ *
+ * @return A potentially shared reference, not guaranteed to be unique.
+ */
+ public SourceIdentifier cachedReference() {
+ return CACHE.getReference(this);
+ }
+
/**
*
* Creates new YANG Schema source identifier for sources without revision.
this(name, NOT_PRESENT_FORMATTED_REVISION);
}
-
/**
* Returns model name
*
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
}
}
+ private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(PotentialSchemaSource.class);
private final Class<? extends T> representation;
private final SourceIdentifier sourceIdentifier;
private final int cost;
return new PotentialSchemaSource<>(sourceIdentifier, representation, cost);
}
+ /**
+ * Return a cached reference to an object equal to this object.
+ *
+ * @return A potentially shared reference, not guaranteed to be unique.
+ */
+ public PotentialSchemaSource<T> cachedReference() {
+ return CACHE.getReference(this);
+ }
+
public SourceIdentifier getSourceIdentifier() {
return sourceIdentifier;
}
@Override
public <T extends SchemaSourceRepresentation> SchemaSourceRegistration<T> registerSchemaSource(final SchemaSourceProvider<? super T> provider, final PotentialSchemaSource<T> source) {
- final AbstractSchemaSourceRegistration<T> ret = new AbstractSchemaSourceRegistration<T>(provider, source) {
+ final PotentialSchemaSource<T> src = source.cachedReference();
+
+ final AbstractSchemaSourceRegistration<T> ret = new AbstractSchemaSourceRegistration<T>(provider, src) {
@Override
protected void removeRegistration() {
- removeSource(source, this);
+ removeSource(src, this);
}
};
- addSource(source, ret);
+ addSource(src, ret);
return ret;
}