*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/eplv10.html
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.model.repo.util;
@GuardedBy("this")
private final Collection<SchemaListenerRegistration> listeners = new ArrayList<>();
- private static final <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> fetchSource(final SourceIdentifier id, final Iterator<AbstractSchemaSourceRegistration<?>> it) {
+ private static <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> fetchSource(final SourceIdentifier id, final Iterator<AbstractSchemaSourceRegistration<?>> it) {
final AbstractSchemaSourceRegistration<?> reg = it.next();
@SuppressWarnings("unchecked")
return fetchSource(id, it);
}
- throw new MissingSchemaSourceException("All available providers exhausted", t);
+ throw new MissingSchemaSourceException("All available providers exhausted", id, t);
}
}), FETCH_MAPPER);
}
public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(final SourceIdentifier id, final Class<T> representation) {
final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs = sources.get(id);
if (srcs == null) {
- return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id));
+ return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(new MissingSchemaSourceException("No providers registered for source" + id, id));
}
// TODO, remove and make sources keep sorted multimap (e.g. ArrayListMultimap with SortedLists)
final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();
if (!regs.hasNext()) {
return Futures.<T, SchemaSourceException>immediateFailedCheckedFuture(
- new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available"));
+ new MissingSchemaSourceException("No providers for source " + id + " representation " + representation + " available", id));
}
CheckedFuture<T, SchemaSourceException> fetchSourceFuture = fetchSource(id, regs);
}
if (m.isEmpty()) {
- sources.remove(m);
+ sources.remove(source.getSourceIdentifier());
}
}
}
@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;
}