X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Frepo%2Futil%2FSchemaSourceTransformer.java;h=28539bbfafad36b722c54cc01ab933939b406efc;hb=c12e09090073384744e8684f23f01f8c64fd307d;hp=355c1956a40a03f6be244d09e577f68168e070cb;hpb=7e571648e27863df485ac2d709d00cf0e5f9f6fe;p=yangtools.git diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java index 355c1956a4..28539bbfaf 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java @@ -7,18 +7,15 @@ */ package org.opendaylight.yangtools.yang.model.repo.util; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.AsyncFunction; -import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; - +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.MoreExecutors; import java.util.HashMap; import java.util.Map; - -import org.opendaylight.yangtools.util.concurrent.ExceptionMapper; -import org.opendaylight.yangtools.util.concurrent.ReflectiveExceptionMapper; import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository; -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.SourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource; @@ -27,15 +24,17 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration; import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry; -public class SchemaSourceTransformer implements SchemaSourceListener, SchemaSourceProvider { - private static final ExceptionMapper MAPPER = ReflectiveExceptionMapper.create("Source transformation", SchemaSourceException.class); +public class SchemaSourceTransformer + implements SchemaSourceListener, SchemaSourceProvider { - public interface Transformation extends AsyncFunction { + @FunctionalInterface + public interface Transformation + extends AsyncFunction { @Override - CheckedFuture apply(final S input) throws Exception; + ListenableFuture apply(S input) throws Exception; } - private final Map, RefcountedRegistration> sources = new HashMap<>(); + private final Map, RefcountedRegistration> availableSources = new HashMap<>(); private final SchemaSourceRegistry consumer; private final SchemaRepository provider; private final AsyncFunction function; @@ -44,17 +43,17 @@ public class SchemaSourceTransformer srcClass, final SchemaSourceRegistry consumer, final Class dstClass, final AsyncFunction function) { - this.provider = Preconditions.checkNotNull(provider); - this.consumer = Preconditions.checkNotNull(consumer); - this.function = Preconditions.checkNotNull(function); - this.srcClass = Preconditions.checkNotNull(srcClass); - this.dstClass = Preconditions.checkNotNull(dstClass); + this.provider = requireNonNull(provider); + this.consumer = requireNonNull(consumer); + this.function = requireNonNull(function); + this.srcClass = requireNonNull(srcClass); + this.dstClass = requireNonNull(dstClass); } @Override - public CheckedFuture getSource(final SourceIdentifier sourceIdentifier) { - final CheckedFuture f = provider.getSchemaSource(sourceIdentifier, srcClass); - return Futures.makeChecked(Futures.transform(f, function), MAPPER); + public ListenableFuture getSource(final SourceIdentifier sourceIdentifier) { + return Futures.transformAsync(provider.getSchemaSource(sourceIdentifier, srcClass), function, + MoreExecutors.directExecutor()); } @Override @@ -81,7 +80,7 @@ public class SchemaSourceTransformer src) { - RefcountedRegistration reg = sources.get(src); + RefcountedRegistration reg = availableSources.get(src); if (reg != null) { reg.incRef(); return; @@ -91,13 +90,13 @@ public class SchemaSourceTransformer r = consumer.registerSchemaSource(this, newSrc); - sources.put(src, new RefcountedRegistration(r)); + availableSources.put(src, new RefcountedRegistration(r)); } private void unregisterSource(final PotentialSchemaSource src) { - final RefcountedRegistration reg = sources.get(src); + final RefcountedRegistration reg = availableSources.get(src); if (reg != null && reg.decRef()) { - sources.remove(src); + availableSources.remove(src); } } }