BUG-9043: Remove use of CheckedFuture from YANG components 62/62262/17
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 24 Aug 2017 10:56:06 +0000 (12:56 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 11 Oct 2017 17:28:43 +0000 (17:28 +0000)
This patch removes all references to CheckedFuture, future-proofing
our codebase for Guava upgrades.

Change-Id: I2e6f4e97a6f06b01573287e7904c1681ede3d729
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
22 files changed:
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java [deleted file]
common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java [deleted file]
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/xpath/LazyXPathExpression.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaContextFactory.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/SchemaRepository.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/spi/SchemaSourceProvider.java
yang/yang-model-export/src/test/java/org/opendaylight/yangtools/yang/model/export/test/SimpleModuleTest.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/AbstractSchemaRepository.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/InMemorySchemaSourceCache.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformer.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCacheTest.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/repo/util/SchemaSourceTransformerTest.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolver.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/rfc6020/repo/YinTextToDomTransformer.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/TextToASTTransformer.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/MultipleRevImportBug6875Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SettableSchemaProvider.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactoryTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaRepositoryTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/YangTextSchemaContextResolverTest.java

diff --git a/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java b/common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFuture.java
deleted file mode 100644 (file)
index ce70f35..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
- *
- * 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/epl-v10.html
- */
-
-package org.opendaylight.yangtools.util.concurrent;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.util.concurrent.AbstractCheckedFuture;
-import com.google.common.util.concurrent.ListenableFuture;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.function.Function;
-import javax.annotation.Nonnull;
-
-/**
- * An implementation of CheckedFuture that provides similar behavior for the <code>get</code> methods
- * that the <code>checkedGet</code> methods provide.
- *
- * <p>For {@link CancellationException} and {@link InterruptedException}, the specified exception mapper
- * is invoked to translate them to the checked exception type.
- *
- * <p>For {@link ExecutionException}, the mapper is invoked to translate the cause to the checked exception
- * and a new ExecutionException is thrown with the translated cause.
- *
- * @author Thomas Pantelis
- *
- * @param <V> The result type returned by this Future's get method
- * @param <X> The checked exception type
- */
-public final class MappingCheckedFuture<V, X extends Exception> extends AbstractCheckedFuture<V, X> {
-
-    private final Function<Exception, X> mapper;
-
-    private MappingCheckedFuture(final ListenableFuture<V> delegate, final Function<Exception, X> mapper) {
-        super(delegate);
-        this.mapper = requireNonNull(mapper);
-    }
-
-    /**
-     * Creates a new <code>MappingCheckedFuture</code> that wraps the given {@link ListenableFuture}
-     * delegate.
-     *
-     * @param delegate the {@link ListenableFuture} to wrap
-     * @param mapper the mapping {@link Function} used to translate exceptions from the delegate
-     * @return a new <code>MappingCheckedFuture</code>
-     */
-    public static <V, X extends Exception> MappingCheckedFuture<V, X> create(
-            final ListenableFuture<V> delegate, final Function<Exception, X> mapper) {
-        return new MappingCheckedFuture<>(delegate, mapper);
-    }
-
-    @Override
-    @SuppressWarnings("checkstyle:parameterName")
-    protected X mapException(@Nonnull final Exception e) {
-        return mapper.apply(e);
-    }
-
-    private ExecutionException wrapInExecutionException(final String message, final Exception ex) {
-        return new ExecutionException(message, mapException(ex));
-    }
-
-    @Override
-    public V get() throws InterruptedException, ExecutionException {
-        try {
-            return super.get();
-        } catch (final InterruptedException e) {
-            Thread.currentThread().interrupt();
-            throw wrapInExecutionException("Operation was interrupted", e);
-        } catch (final CancellationException e) {
-            throw wrapInExecutionException("Operation was cancelled", e);
-        } catch (final ExecutionException e) {
-            throw wrapInExecutionException(e.getMessage(), e);
-        }
-    }
-
-    @Override
-    public V get(final long timeout, @Nonnull final TimeUnit unit)
-            throws InterruptedException, ExecutionException, TimeoutException {
-        try {
-            return super.get(timeout, unit);
-        } catch (final InterruptedException e) {
-            Thread.currentThread().interrupt();
-            throw wrapInExecutionException("Operation was interrupted", e);
-        } catch (final CancellationException e) {
-            throw wrapInExecutionException("Operation was cancelled", e);
-        } catch (final ExecutionException e) {
-            throw wrapInExecutionException(e.getMessage(), e);
-        }
-    }
-}
diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/concurrent/MappingCheckedFutureTest.java
deleted file mode 100644 (file)
index 068f825..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
- *
- * 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/epl-v10.html
- */
-
-package org.opendaylight.yangtools.util.concurrent;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.SettableFuture;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-import org.junit.Test;
-
-/**
- * Unit tests for MappingCheckedFuture.
- *
- * @author Thomas Pantelis
- */
-public class MappingCheckedFutureTest {
-
-    interface FutureInvoker {
-        void invokeGet(CheckedFuture<?,?> future) throws Exception;
-
-        Throwable extractWrappedTestEx(Exception from);
-    }
-
-    static class TestException extends Exception {
-        private static final long serialVersionUID = 1L;
-
-        TestException(final String message, final Throwable cause) {
-            super(message, cause);
-        }
-    }
-
-    static final ExceptionMapper<TestException> MAPPER = new ExceptionMapper<TestException>(
-                                                                      "Test", TestException.class) {
-
-        @Override
-        protected TestException newWithCause(final String message, final Throwable cause) {
-            return new TestException(message, cause);
-        }
-    };
-
-    static final FutureInvoker GET = new FutureInvoker() {
-        @Override
-        public void invokeGet(final CheckedFuture<?, ?> future) throws Exception {
-            future.get();
-        }
-
-        @Override
-        public Throwable extractWrappedTestEx(final Exception from) {
-            if (from instanceof ExecutionException) {
-                return from.getCause();
-            }
-
-            return from;
-        }
-    };
-
-    static final FutureInvoker TIMED_GET = new FutureInvoker() {
-        @Override
-        public void invokeGet(final CheckedFuture<?, ?> future) throws Exception {
-            future.get(1, TimeUnit.HOURS);
-        }
-
-        @Override
-        public Throwable extractWrappedTestEx(final Exception from) {
-            if (from instanceof ExecutionException) {
-                return from.getCause();
-            }
-
-            return from;
-        }
-    };
-
-    static final FutureInvoker CHECKED_GET = new FutureInvoker() {
-        @Override
-        public void invokeGet(final CheckedFuture<?,?> future) throws Exception {
-            future.checkedGet();
-        }
-
-        @Override
-        public Throwable extractWrappedTestEx(final Exception from) {
-            return from;
-        }
-    };
-
-    static final FutureInvoker TIMED_CHECKED_GET = new FutureInvoker() {
-        @Override
-        public void invokeGet(final CheckedFuture<?,?> future) throws Exception {
-            future.checkedGet(50, TimeUnit.MILLISECONDS);
-        }
-
-        @Override
-        public Throwable extractWrappedTestEx(final Exception from) {
-            return from;
-        }
-    };
-
-    @Test
-    public void testGet() throws Exception {
-        SettableFuture<String> delegate = SettableFuture.create();
-        MappingCheckedFuture<String,TestException> future = MappingCheckedFuture.create(delegate, MAPPER);
-        delegate.set("test");
-        assertEquals("get", "test", future.get());
-    }
-
-    @Test
-    public void testGetWithExceptions() throws Exception {
-        testExecutionException(GET, new RuntimeException());
-        testExecutionException(GET, new TestException("mock", null));
-        testCancellationException(GET);
-        testInterruptedException(GET);
-    }
-
-    @Test
-    public void testTimedGet() throws Exception {
-        SettableFuture<String> delegate = SettableFuture.create();
-        MappingCheckedFuture<String,TestException> future = MappingCheckedFuture.create(delegate, MAPPER);
-        delegate.set("test");
-        assertEquals("get", "test", future.get(50, TimeUnit.MILLISECONDS));
-    }
-
-    @Test
-    public void testTimedGetWithExceptions() throws Exception {
-        testExecutionException(TIMED_GET, new RuntimeException());
-        testCancellationException(TIMED_GET);
-        testInterruptedException(TIMED_GET);
-    }
-
-    @Test
-    public void testCheckedGetWithExceptions() throws Exception {
-        testExecutionException(CHECKED_GET, new RuntimeException());
-        testCancellationException(CHECKED_GET);
-        testInterruptedException(CHECKED_GET);
-    }
-
-    @Test
-    public void testTimedCheckedWithExceptions() throws Exception {
-        testExecutionException(TIMED_CHECKED_GET, new RuntimeException());
-        testCancellationException(TIMED_CHECKED_GET);
-        testInterruptedException(TIMED_CHECKED_GET);
-    }
-
-    @SuppressWarnings("checkstyle:illegalCatch")
-    private static void testExecutionException(final FutureInvoker invoker, final Throwable cause) {
-        SettableFuture<String> delegate = SettableFuture.create();
-        MappingCheckedFuture<String, TestException> mappingFuture = MappingCheckedFuture.create(delegate, MAPPER);
-
-        delegate.setException(cause);
-
-        try {
-            invoker.invokeGet(mappingFuture);
-            fail("Expected exception thrown");
-        } catch (Exception e) {
-            Throwable expectedTestEx = invoker.extractWrappedTestEx(e);
-            assertNotNull("Expected returned exception is null", expectedTestEx);
-            assertEquals("Exception type", TestException.class, expectedTestEx.getClass());
-
-            if (cause instanceof TestException) {
-                assertNull("Expected null cause", expectedTestEx.getCause());
-            } else {
-                assertSame("TestException cause", cause, expectedTestEx.getCause());
-            }
-        }
-    }
-
-    @SuppressWarnings("checkstyle:illegalCatch")
-    private static void testCancellationException(final FutureInvoker invoker) {
-        SettableFuture<String> delegate = SettableFuture.create();
-        MappingCheckedFuture<String, TestException> mappingFuture = MappingCheckedFuture.create(delegate, MAPPER);
-
-        mappingFuture.cancel(false);
-
-        try {
-            invoker.invokeGet(mappingFuture);
-            fail("Expected exception thrown");
-        } catch (Exception e) {
-            Throwable expectedTestEx = invoker.extractWrappedTestEx(e);
-            assertNotNull("Expected returned exception is null", expectedTestEx);
-            assertEquals("Exception type", TestException.class, expectedTestEx.getClass());
-            assertEquals("TestException cause type", CancellationException.class, expectedTestEx.getCause().getClass());
-        }
-    }
-
-    @SuppressWarnings("checkstyle:illegalCatch")
-    private static void testInterruptedException(final FutureInvoker invoker) throws Exception {
-        SettableFuture<String> delegate = SettableFuture.create();
-        final MappingCheckedFuture<String, TestException> mappingFuture = MappingCheckedFuture.create(delegate, MAPPER);
-
-        final AtomicReference<AssertionError> assertError = new AtomicReference<>();
-        final CountDownLatch doneLatch = new CountDownLatch(1);
-        Thread thread = new Thread() {
-            @Override
-            public void run() {
-                try {
-                    doInvoke();
-                } catch (AssertionError e) {
-                    assertError.set(e);
-                } finally {
-                    doneLatch.countDown();
-                }
-            }
-
-            void doInvoke() {
-                try {
-                    invoker.invokeGet(mappingFuture);
-                    fail("Expected exception thrown");
-                } catch (Exception e) {
-                    Throwable expectedTestEx = invoker.extractWrappedTestEx(e);
-                    assertNotNull("Expected returned exception is null", expectedTestEx);
-                    assertEquals("Exception type", TestException.class, expectedTestEx.getClass());
-                    assertEquals("TestException cause type", InterruptedException.class,
-                                  expectedTestEx.getCause().getClass());
-                }
-            }
-        };
-        thread.start();
-
-        thread.interrupt();
-        assertTrue("get call completed", doneLatch.await(5, TimeUnit.SECONDS));
-
-        if (assertError.get() != null) {
-            throw assertError.get();
-        }
-    }
-}
index b58a288c47f45a4db3a3d2a087767c00ab59d639..90faba1eca037bce0a6c2925fda50df099152a99 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema.xpath;
 
 import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Optional;
 import java.util.concurrent.Future;
 import javax.annotation.Nonnull;
@@ -52,6 +52,6 @@ public interface LazyXPathExpression {
      * @throws NullPointerException if any of the arguments are null
      * @throws IllegalArgumentException if the path does not match the path at which this expression was compiled
      */
-    CheckedFuture<Optional<? extends XPathResult<?>>, XPathExpressionException> evaluateLazily(
-            @Nonnull XPathDocument document, @Nonnull YangInstanceIdentifier path);
+    ListenableFuture<Optional<? extends XPathResult<?>>> evaluateLazily(@Nonnull XPathDocument document,
+            @Nonnull YangInstanceIdentifier path);
 }
index 91dfc946f4c004df57ed157ba93c3e04d8b02c06..5fac8367e813967b4311501c7cb3703a56d44117 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collection;
 import java.util.Set;
 import javax.annotation.Nonnull;
@@ -32,7 +32,7 @@ public interface SchemaContextFactory {
      *         with an explanation why the creation of the schema context
      *         failed.
      */
-    default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
+    default ListenableFuture<SchemaContext> createSchemaContext(
             @Nonnull final Collection<SourceIdentifier> requiredSources) {
         return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE);
     }
@@ -49,7 +49,7 @@ public interface SchemaContextFactory {
      *         with an explanation why the creation of the schema context
      *         failed.
      */
-    default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
+    default ListenableFuture<SchemaContext> createSchemaContext(
             final Collection<SourceIdentifier> requiredSources, final StatementParserMode statementParserMode) {
         return createSchemaContext(requiredSources, statementParserMode, null);
     }
@@ -67,7 +67,7 @@ public interface SchemaContextFactory {
      *         with an explanation why the creation of the schema context
      *         failed.
      */
-    default CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
+    default ListenableFuture<SchemaContext> createSchemaContext(
             @Nonnull final Collection<SourceIdentifier> requiredSources, final Set<QName> supportedFeatures) {
         return createSchemaContext(requiredSources, StatementParserMode.DEFAULT_MODE, supportedFeatures);
     }
@@ -87,7 +87,6 @@ public interface SchemaContextFactory {
      *         with an explanation why the creation of the schema context
      *         failed.
      */
-    CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
-            Collection<SourceIdentifier> requiredSources, StatementParserMode statementParserMode,
-            Set<QName> supportedFeatures);
+    ListenableFuture<SchemaContext> createSchemaContext(Collection<SourceIdentifier> requiredSources,
+            StatementParserMode statementParserMode, Set<QName> supportedFeatures);
 }
index 673929951f55c32dd9ea68614d7ff67eb86aeca8..cefd55868eeb84b392d66d284b3ca16dd217e897 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.yangtools.yang.model.repo.api;
 
 import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -29,6 +29,6 @@ public interface SchemaRepository {
      */
     SchemaContextFactory createSchemaContextFactory(@Nonnull SchemaSourceFilter filter);
 
-    <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(
-            @Nonnull SourceIdentifier id, @Nonnull Class<T> represetation);
+    <T extends SchemaSourceRepresentation> ListenableFuture<T> getSchemaSource(@Nonnull SourceIdentifier id,
+            @Nonnull Class<T> represetation);
 }
index 00f8040ff72e35088abb977d92b16c1edf151983..06c0a2a5cc9725ab06c369b93ef7fcaedfbe9b7f 100644 (file)
@@ -8,9 +8,8 @@
 package org.opendaylight.yangtools.yang.model.repo.spi;
 
 import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 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.SourceIdentifier;
 
@@ -44,8 +43,7 @@ public interface SchemaSourceProvider<T extends SchemaSourceRepresentation> {
      * this different invocation of this method may produce different results.
      *
      * @param sourceIdentifier source identifier
-     * @return source representation if supplied YANG module is available
-     *
+     * @return future source representation, if supplied YANG module is available
      */
-    CheckedFuture<? extends T, SchemaSourceException> getSource(SourceIdentifier sourceIdentifier);
+    ListenableFuture<? extends T> getSource(SourceIdentifier sourceIdentifier);
 }
index d1f4200239db915aba16e0f895a6df1bd0536a7b..c34ddae9299781a340f4c0dd6913e55a8ddebe7e 100644 (file)
@@ -86,7 +86,7 @@ public class SimpleModuleTest {
     }
 
     private void testSetOfModules(final Collection<SourceIdentifier> source) throws Exception {
-        final SchemaContext schemaContext = schemaContextFactory.createSchemaContext(source).checkedGet();
+        final SchemaContext schemaContext = schemaContextFactory.createSchemaContext(source).get();
         final File outDir = new File("target/collection");
         outDir.mkdirs();
         for (final Module module : schemaContext.getModules()) {
index 1f211bfaca7fb12537e2f17a160d4e292210208a..f5672d4e23c514c2f02b0ce86d4ff51ca739ce9b 100644 (file)
@@ -12,7 +12,6 @@ import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ListMultimap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -26,11 +25,8 @@ import java.util.Iterator;
 import java.util.Map;
 import javax.annotation.Nonnull;
 import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
-import org.opendaylight.yangtools.util.concurrent.ReflectiveExceptionMapper;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 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.SchemaSourceFilter;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -51,8 +47,6 @@ import org.slf4j.LoggerFactory;
 @Beta
 public abstract class AbstractSchemaRepository implements SchemaRepository, SchemaSourceRegistry {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractSchemaRepository.class);
-    private static final ExceptionMapper<SchemaSourceException> FETCH_MAPPER = ReflectiveExceptionMapper.create(
-            "Schema source fetch", SchemaSourceException.class);
 
     /*
      * Source identifier -> representation -> provider map. We usually are looking for
@@ -86,7 +80,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
     }
 
     @Override
-    public <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> getSchemaSource(
+    public <T extends SchemaSourceRepresentation> ListenableFuture<T> getSchemaSource(
             @Nonnull final SourceIdentifier id, @Nonnull final Class<T> representation) {
         final ArrayList<AbstractSchemaSourceRegistration<?>> sortedSchemaSourceRegistrations;
 
@@ -94,8 +88,8 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
             final ListMultimap<Class<? extends SchemaSourceRepresentation>, AbstractSchemaSourceRegistration<?>> srcs =
                 sources.get(id);
             if (srcs == null) {
-                return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException(
-                            "No providers registered for source" + id, id));
+                return Futures.immediateFailedFuture(new MissingSchemaSourceException(
+                    "No providers registered for source" + id, id));
             }
 
             sortedSchemaSourceRegistrations = Lists.newArrayList(srcs.get(representation));
@@ -106,7 +100,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
 
         final Iterator<AbstractSchemaSourceRegistration<?>> regs = sortedSchemaSourceRegistrations.iterator();
         if (!regs.hasNext()) {
-            return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException(
+            return Futures.immediateFailedFuture(new MissingSchemaSourceException(
                         "No providers for source " + id + " representation " + representation + " available", id));
         }
 
@@ -127,7 +121,7 @@ public abstract class AbstractSchemaRepository implements SchemaRepository, Sche
             }
         }, MoreExecutors.directExecutor());
 
-        return Futures.makeChecked(fetchSourceFuture, FETCH_MAPPER);
+        return fetchSourceFuture;
     }
 
     private synchronized <T extends SchemaSourceRepresentation> void addSource(final PotentialSchemaSource<T> source,
index 5ad577a5b4ec8d045b3ea5c454389f08608c103c..85bcb519fc90f28abbd81e7617f8bf00871ceba9 100644 (file)
@@ -13,8 +13,8 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
@@ -38,7 +38,6 @@ import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-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.api.YangTextSchemaSource;
@@ -116,19 +115,18 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
     }
 
     @Override
-    public synchronized CheckedFuture<? extends T, SchemaSourceException> getSource(
+    public synchronized ListenableFuture<? extends T> getSource(
             final SourceIdentifier sourceIdentifier) {
         final File file = sourceIdToFile(sourceIdentifier, storageDirectory);
         if (file.exists() && file.canRead()) {
             LOG.trace("Source {} found in cache as {}", sourceIdentifier, file);
             final SchemaSourceRepresentation restored = STORAGE_ADAPTERS.get(representation).restore(sourceIdentifier,
                     file);
-            return Futures.immediateCheckedFuture(representation.cast(restored));
+            return Futures.immediateFuture(representation.cast(restored));
         }
 
         LOG.debug("Source {} not found in cache as {}", sourceIdentifier, file);
-        return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found",
-                    sourceIdentifier));
+        return Futures.immediateFailedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
     }
 
     @Override
index 6f510457ff887d1ab51287d5951b4f32d1a83e93..947e06f2c2f91e08e31e49fdca3c0c602795c687 100644 (file)
@@ -12,14 +12,13 @@ import com.google.common.base.FinalizablePhantomReference;
 import com.google.common.base.FinalizableReferenceQueue;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 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.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource.Costs;
@@ -52,14 +51,13 @@ public class InMemorySchemaSourceCache<T extends SchemaSourceRepresentation> ext
     }
 
     @Override
-    public CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
+    public ListenableFuture<? extends T> getSource(final SourceIdentifier sourceIdentifier) {
         final T present = cache.getIfPresent(sourceIdentifier);
         if (present != null) {
-            return Futures.immediateCheckedFuture(present);
+            return Futures.immediateFuture(present);
         }
 
-        return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException("Source not found",
-                    sourceIdentifier));
+        return Futures.immediateFailedFuture(new MissingSchemaSourceException("Source not found", sourceIdentifier));
     }
 
     @Override
index 68bad933d084b78d0c12459a04ce9a3cac429311..bb7da5593c8997fcae63b6f1cc7856a5e5643312 100644 (file)
@@ -10,16 +10,13 @@ package org.opendaylight.yangtools.yang.model.repo.util;
 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 javax.annotation.Nonnull;
-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;
@@ -30,14 +27,12 @@ import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
 
 public class SchemaSourceTransformer<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
         implements SchemaSourceListener, SchemaSourceProvider<D> {
-    private static final ExceptionMapper<SchemaSourceException> MAPPER = ReflectiveExceptionMapper.create(
-            "Source transformation", SchemaSourceException.class);
 
     @FunctionalInterface
     public interface Transformation<S extends SchemaSourceRepresentation, D extends SchemaSourceRepresentation>
             extends AsyncFunction<S, D> {
         @Override
-        CheckedFuture<D, SchemaSourceException> apply(@Nonnull S input) throws Exception;
+        ListenableFuture<D> apply(@Nonnull S input) throws Exception;
     }
 
     private final Map<PotentialSchemaSource<?>, RefcountedRegistration> sources = new HashMap<>();
@@ -57,9 +52,9 @@ public class SchemaSourceTransformer<S extends SchemaSourceRepresentation, D ext
     }
 
     @Override
-    public CheckedFuture<D, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
-        final CheckedFuture<S, SchemaSourceException> f = provider.getSchemaSource(sourceIdentifier, srcClass);
-        return Futures.makeChecked(Futures.transformAsync(f, function, MoreExecutors.directExecutor()), MAPPER);
+    public ListenableFuture<D> getSource(final SourceIdentifier sourceIdentifier) {
+        return Futures.transformAsync(provider.getSchemaSource(sourceIdentifier, srcClass), function,
+            MoreExecutors.directExecutor());
     }
 
     @Override
index 9b715f09d193eb65b3b08f579e478ea76acfdc4a..304d0a8c9ee0f5fb1582258fe6aafe64fcd52f25 100644 (file)
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
 import com.google.common.base.MoreObjects;
 import com.google.common.collect.Collections2;
 import com.google.common.io.Files;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -40,7 +39,6 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
@@ -198,10 +196,9 @@ public class FilesystemSchemaSourceCacheTest {
         final YangTextSchemaSource source = new TestingYangSource("test", "2013-12-12", content);
         cache.offer(source);
         final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("test", "2013-12-12");
-        final CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> checked = cache
-                .getSource(sourceIdentifier);
+        final ListenableFuture<? extends YangTextSchemaSource> checked = cache.getSource(sourceIdentifier);
         Assert.assertNotNull(checked);
-        final YangTextSchemaSource checkedGet = checked.checkedGet();
+        final YangTextSchemaSource checkedGet = checked.get();
         Assert.assertEquals(sourceIdentifier, checkedGet.getIdentifier());
         Assert.assertTrue(checked.isDone());
     }
index a0ac6000d1c7afcc4f83990d64b781a5a4ee2ba9..440067d4795043b78994790543cc0c8b2f4acc7e 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.model.repo.util;
 
 import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Arrays;
 import java.util.concurrent.Future;
@@ -22,7 +21,6 @@ import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
 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.SchemaSourceFilter;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -133,9 +131,9 @@ public class SchemaSourceTransformerTest {
         }
 
         @Override
-        public CheckedFuture<? extends YangSchemaSourceRepresentation, SchemaSourceException> getSource(
+        public ListenableFuture<? extends YangSchemaSourceRepresentation> getSource(
                 final SourceIdentifier sourceIdentifier) {
-            return Mockito.mock(CheckedFuture.class);
+            return Mockito.mock(ListenableFuture.class);
         }
 
     }
index c5c6bdec5d6065b8ceb3398bc96b59e4eb021589..e31305a79341a8be353d45c11ccb4014da517bbc 100644 (file)
@@ -16,7 +16,6 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.AsyncFunction;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -71,16 +70,14 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
     }
 
     @Override
-    public CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
-            final Collection<SourceIdentifier> requiredSources, final StatementParserMode statementParserMode,
-            final Set<QName> supportedFeatures) {
+    public ListenableFuture<SchemaContext> createSchemaContext(final Collection<SourceIdentifier> requiredSources,
+            final StatementParserMode statementParserMode, final Set<QName> supportedFeatures) {
         return createSchemaContext(requiredSources,
                 statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache,
                 new AssembleSources(Optional.ofNullable(supportedFeatures), statementParserMode));
     }
 
-    private CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(
-            final Collection<SourceIdentifier> requiredSources,
+    private ListenableFuture<SchemaContext> createSchemaContext(final Collection<SourceIdentifier> requiredSources,
             final Cache<Collection<SourceIdentifier>, SchemaContext> cache,
             final AsyncFunction<List<ASTSchemaSource>, SchemaContext> assembleSources) {
         // Make sources unique
@@ -89,7 +86,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
         final SchemaContext existing = cache.getIfPresent(uniqueSourceIdentifiers);
         if (existing != null) {
             LOG.debug("Returning cached context {}", existing);
-            return Futures.immediateCheckedFuture(existing);
+            return Futures.immediateFuture(existing);
         }
 
         // Request all sources be loaded
@@ -119,7 +116,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
             }
         }, MoreExecutors.directExecutor());
 
-        return Futures.makeChecked(cf, MAPPER);
+        return cf;
     }
 
     private ListenableFuture<ASTSchemaSource> requestSource(final SourceIdentifier identifier) {
@@ -215,7 +212,10 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
             }
 
             final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(
-                statementParserMode, supportedFeatures);
+                statementParserMode);
+            if (supportedFeatures.isPresent()) {
+                reactor.setSupportedFeatures(supportedFeatures.get());
+            }
 
             for (final Entry<SourceIdentifier, ASTSchemaSource> e : srcs.entrySet()) {
                 final ASTSchemaSource ast = e.getValue();
@@ -234,7 +234,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
                 throw new SchemaResolutionException("Failed to resolve required models", ex.getSourceIdentifier(), ex);
             }
 
-            return Futures.immediateCheckedFuture(schemaContext);
+            return Futures.immediateFuture(schemaContext);
         }
     }
 }
index 6c0a07018715df27df5f93030f39ba464179c6a8..c8abbffdb67f6a1f6aff6c10d20d0a2e31c094c2 100644 (file)
@@ -12,11 +12,12 @@ import static com.google.common.base.Preconditions.checkArgument;
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -24,6 +25,7 @@ import java.util.Collection;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
@@ -229,14 +231,17 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
             } while (ver != version);
 
             while (true) {
-                final CheckedFuture<SchemaContext, SchemaResolutionException> f = factory.createSchemaContext(sources,
-                    statementParserMode);
+                final ListenableFuture<SchemaContext> f = factory.createSchemaContext(sources, statementParserMode);
                 try {
-                    sc = Optional.of(f.checkedGet());
+                    sc = Optional.of(f.get());
                     break;
-                } catch (SchemaResolutionException e) {
+                } catch (InterruptedException e) {
+                    throw new RuntimeException("Interrupted while assembling schema context", e);
+                } catch (ExecutionException e) {
                     LOG.info("Failed to fully assemble schema context for {}", sources, e);
-                    sources = e.getResolvedSources();
+                    final Throwable cause = e.getCause();
+                    Verify.verify(cause instanceof SchemaResolutionException);
+                    sources = ((SchemaResolutionException) cause).getResolvedSources();
                 }
             }
 
@@ -254,17 +259,17 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
     }
 
     @Override
-    public synchronized CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(
+    public synchronized ListenableFuture<YangTextSchemaSource> getSource(
             final SourceIdentifier sourceIdentifier) {
         final Collection<YangTextSchemaSource> ret = texts.get(sourceIdentifier);
 
         LOG.debug("Lookup {} result {}", sourceIdentifier, ret);
         if (ret.isEmpty()) {
-            return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException(
+            return Futures.immediateFailedFuture(new MissingSchemaSourceException(
                 "URL for " + sourceIdentifier + " not registered", sourceIdentifier));
         }
 
-        return Futures.immediateCheckedFuture(ret.iterator().next());
+        return Futures.immediateFuture(ret.iterator().next());
     }
 
     /**
@@ -289,8 +294,22 @@ public final class YangTextSchemaContextResolver implements AutoCloseable, Schem
     @Beta
     public SchemaContext trySchemaContext(final StatementParserMode statementParserMode)
             throws SchemaResolutionException {
-        final SchemaContextFactory factory = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-        return factory.createSchemaContext(ImmutableSet.copyOf(requiredSources), statementParserMode).checkedGet();
+        final ListenableFuture<SchemaContext> future = repository
+                .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT)
+                .createSchemaContext(ImmutableSet.copyOf(requiredSources), statementParserMode);
+
+        try {
+            return future.get();
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Interrupted while waiting for SchemaContext assembly", e);
+        } catch (ExecutionException e) {
+            final Throwable cause = e.getCause();
+            if (cause instanceof SchemaResolutionException) {
+                throw (SchemaResolutionException) cause;
+            }
+
+            throw new SchemaResolutionException("Failed to assemble SchemaContext", e);
+        }
     }
 
     @Override
index f8a2e3d9f6a5388c2eb1ba3e862cc80385d194ed..daafc7e9ccd519f5e83da0513927d124b99f66bb 100644 (file)
@@ -32,7 +32,7 @@ import org.xml.sax.helpers.DefaultHandler;
 public final class YinTextToDomTransformer extends SchemaSourceTransformer<YinTextSchemaSource, YinDomSchemaSource> {
     private YinTextToDomTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
         super(provider, YinTextSchemaSource.class, consumer, YinDomSchemaSource.class,
-            input -> Futures.immediateCheckedFuture(transformSource(input)));
+            input -> Futures.immediateFuture(transformSource(input)));
     }
 
     public static YinTextToDomTransformer create(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
index 3cf9e1c83885d0a409c8a152a9ca6210350bcef3..12e486f3add4ac91f90088c48d1c288329a2a2b8 100644 (file)
@@ -9,11 +9,9 @@
 package org.opendaylight.yangtools.yang.parser.util;
 
 import com.google.common.annotations.Beta;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import java.io.IOException;
 import java.util.Optional;
-import javax.annotation.Nonnull;
 import org.antlr.v4.runtime.ParserRuleContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
@@ -31,45 +29,11 @@ import org.slf4j.LoggerFactory;
  */
 @Beta
 public final class TextToASTTransformer extends SchemaSourceTransformer<YangTextSchemaSource, ASTSchemaSource> {
-
-    /**
-     * A text-to-AST Transformation.
-     *
-     * @deprecated Use {@link TextToASTTransformer#transformText(YangTextSchemaSource)} instead.
-     */
-    @Deprecated
-    public static final class TextToASTTransformation implements Transformation<YangTextSchemaSource, ASTSchemaSource> {
-        @Override
-        public CheckedFuture<ASTSchemaSource, SchemaSourceException> apply(@Nonnull final YangTextSchemaSource input)
-                throws IOException, YangSyntaxErrorException {
-            final YangStatementStreamSource src = YangStatementStreamSource.create(input);
-
-            final ParserRuleContext ctx = src.getYangAST();
-            LOG.debug("Model {} parsed successfully", input);
-
-            //:TODO missing validation (YangModelBasicValidationListener should be re-implemented to new parser)
-
-            final Optional<String> opt = input.getSymbolicName();
-            final ASTSchemaSource result = opt.isPresent()
-                    ? ASTSchemaSource.create(opt.get(), input.getIdentifier(), ctx)
-                            : ASTSchemaSource.create(input.getIdentifier(), ctx);
-
-            return Futures.immediateCheckedFuture(result);
-        }
-    }
-
-    /**
-     * Singleton instance of {@link TextToASTTransformation}.
-     *
-     * @deprecated Use {@link TextToASTTransformer#transformText(YangTextSchemaSource)} instead.
-     */
-    @Deprecated
-    public static final TextToASTTransformation TRANSFORMATION = new TextToASTTransformation();
-
     private static final Logger LOG = LoggerFactory.getLogger(TextToASTTransformer.class);
 
     private TextToASTTransformer(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
-        super(provider, YangTextSchemaSource.class, consumer, ASTSchemaSource.class, TRANSFORMATION);
+        super(provider, YangTextSchemaSource.class, consumer, ASTSchemaSource.class,
+            input -> Futures.immediateFuture(transformText(input)));
     }
 
     public static TextToASTTransformer create(final SchemaRepository provider, final SchemaSourceRegistry consumer) {
@@ -78,6 +42,16 @@ public final class TextToASTTransformer extends SchemaSourceTransformer<YangText
 
     public static ASTSchemaSource transformText(final YangTextSchemaSource text) throws SchemaSourceException,
             IOException, YangSyntaxErrorException {
-        return TRANSFORMATION.apply(text).checkedGet();
+        final YangStatementStreamSource src = YangStatementStreamSource.create(text);
+        final ParserRuleContext ctx = src.getYangAST();
+        LOG.debug("Model {} parsed successfully", text);
+
+        // TODO: missing validation (YangModelBasicValidationListener should be re-implemented to new parser)
+
+        final Optional<String> opt = text.getSymbolicName();
+        final ASTSchemaSource result = opt.isPresent() ? ASTSchemaSource.create(opt.get(), text.getIdentifier(), ctx)
+                : ASTSchemaSource.create(text.getIdentifier(), ctx);
+
+        return result;
     }
 }
index 9c2a3e86e3e0441c20fbae88606c2fc0f080c253..0a1ad9b1b868774e1059ccb027bae297a97510b6 100644 (file)
@@ -14,8 +14,8 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -23,7 +23,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
@@ -100,18 +99,18 @@ public class MultipleRevImportBug6875Test {
         setAndRegister(sharedSchemaRepository, bar1);
         setAndRegister(sharedSchemaRepository, bar2);
 
-        final SchemaContextFactory fact = sharedSchemaRepository
-                .createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
-
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContextFuture = fact
-                .createSchemaContext(ImmutableList.of(foo.getId(), bar1.getId(), bar2.getId()));
+        final SchemaContextFactory fact = sharedSchemaRepository.createSchemaContextFactory(
+                SchemaSourceFilter.ALWAYS_ACCEPT);
+        final ListenableFuture<SchemaContext> schemaContextFuture = fact.createSchemaContext(
+                ImmutableList.of(foo.getId(), bar1.getId(), bar2.getId()));
         assertTrue(schemaContextFuture.isDone());
 
         try {
-            schemaContextFuture.checkedGet();
+            schemaContextFuture.get();
             fail("Test should fail due to invalid imports of yang source.");
-        } catch (final SchemaResolutionException e) {
-            assertTrue(e.getCause().getMessage().startsWith("Module:bar imported twice with different revisions"));
+        } catch (final ExecutionException e) {
+            assertTrue(e.getCause().getMessage().startsWith(
+                "Module:bar imported twice with different revisions"));
         }
     }
 
index 2b9595b0618281ca59ccd1771cba0316fb03b758..9f48a189d82c326f37f6ec209bb4a871f4c329b0 100644 (file)
@@ -8,10 +8,8 @@
 
 package org.opendaylight.yangtools.yang.parser.repo;
 
-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.SettableFuture;
-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;
@@ -43,8 +41,8 @@ class SettableSchemaProvider<T extends SchemaSourceRepresentation> implements Sc
     }
 
     @Override
-    public CheckedFuture<T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
-        return Futures.makeChecked(future, input -> new SchemaSourceException("Failed", input));
+    public ListenableFuture<T> getSource(final SourceIdentifier sourceIdentifier) {
+        return future;
     }
 
     public T getSchemaSourceRepresentation() {
index 7de48bfabc863be8c65ec43986055dd530489fe5..7728b4ad710b9c54cfe4b0a8f1a968a8007cbfa5 100644 (file)
@@ -46,10 +46,10 @@ public class SharedSchemaContextFactoryTest {
         final TextToASTTransformer transformer = TextToASTTransformer.create(repository, repository);
         repository.registerSchemaSourceListener(transformer);
 
-        repository.registerSchemaSource(sourceIdentifier -> Futures.immediateCheckedFuture(source1),
+        repository.registerSchemaSource(sourceIdentifier -> Futures.immediateFuture(source1),
             PotentialSchemaSource.create(s1, YangTextSchemaSource.class, 1));
 
-        repository.registerSchemaSource(sourceIdentifier -> Futures.immediateCheckedFuture(source2),
+        repository.registerSchemaSource(sourceIdentifier -> Futures.immediateFuture(source2),
             PotentialSchemaSource.create(s2, YangTextSchemaSource.class, 1));
     }
 
index 8bbbd7e1ac10c8c01a3a2d83a88b137854341b5f..93ea3cd3c9d694e99e237c0fc55c8a66063ce220 100644 (file)
@@ -26,7 +26,6 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.io.Files;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -47,7 +46,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
 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.api.YangTextSchemaSource;
@@ -167,12 +165,12 @@ public class SharedSchemaRepositoryTest {
         final Throwable ex = new IllegalStateException("failed schema");
         remoteInetTypesYang.setException(ex);
 
-        final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContextFuture =
-                fact.createSchemaContext(ImmutableList.of(remoteInetTypesYang.getId()));
+        final ListenableFuture<SchemaContext> schemaContextFuture = fact.createSchemaContext(
+            ImmutableList.of(remoteInetTypesYang.getId()));
 
         try {
-            schemaContextFuture.checkedGet();
-        } catch (final SchemaResolutionException e) {
+            schemaContextFuture.get();
+        } catch (final ExecutionException e) {
             assertNotNull(e.getCause());
             assertNotNull(e.getCause().getCause());
             assertSame(ex, e.getCause().getCause());
@@ -274,7 +272,7 @@ public class SharedSchemaRepositoryTest {
 
         final SourceIdentifier runningId = RevisionSourceIdentifier.create("running", Optional.of("2012-12-12"));
 
-        sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> Futures.immediateCheckedFuture(
+        sharedSchemaRepository.registerSchemaSource(sourceIdentifier -> Futures.immediateFuture(
             new YangTextSchemaSource(runningId) {
                 @Override
                 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
index 9d158ab7cdbb6ca7a0dcb3f19edc072d4d78f33f..6eff10919f85361bca413672119c7a640418e6d1 100644 (file)
@@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.io.IOException;
 import java.net.URL;
@@ -22,7 +21,6 @@ import java.util.concurrent.ExecutionException;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
-import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -73,14 +71,14 @@ public class YangTextSchemaContextResolverTest {
         assertEquals(bazModuleId, baz.get().getIdentifier());
 
         final SourceIdentifier foobarModuleId = RevisionSourceIdentifier.create("foobar", "2016-09-26");
-        final CheckedFuture<YangTextSchemaSource, SchemaSourceException> foobar =
-                yangTextSchemaContextResolver.getSource(foobarModuleId);
+        final ListenableFuture<YangTextSchemaSource> foobar = yangTextSchemaContextResolver.getSource(foobarModuleId);
         assertTrue(foobar.isDone());
         try {
-            foobar.checkedGet();
+            foobar.get();
             fail("A MissingSchemaSourceException should have been thrown.");
-        } catch (MissingSchemaSourceException ex) {
-            assertEquals("URL for RevisionSourceIdentifier [name=foobar@2016-09-26] not registered", ex.getMessage());
+        } catch (ExecutionException e) {
+            assertEquals("URL for RevisionSourceIdentifier [name=foobar@2016-09-26] not registered",
+                e.getCause().getMessage());
         }
 
         Optional<SchemaContext> schemaContextOptional = yangTextSchemaContextResolver.getSchemaContext();