List of usage examples for com.google.common.util.concurrent Futures immediateCheckedFuture
@GwtIncompatible("TODO") @CheckReturnValue public static <V, X extends Exception> CheckedFuture<V, X> immediateCheckedFuture(@Nullable V value)
From source file:org.opendaylight.controller.md.sal.dom.store.impl.replica.SnapshotBackedReadTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read( final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed")); }/*from ww w .j a v a 2 s .c om*/ try { return Futures.immediateCheckedFuture(snapshot.readNode(path)); } catch (Exception e) { //LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e)); } }
From source file:org.opendaylight.controller.md.sal.dom.store.impl.replica.SnapshotBackedReadWriteTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read( final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); final Optional<NormalizedNode<?, ?>> result; try {/*from w w w . j a va 2s.c o m*/ result = readSnapshotNode(path); } catch (Exception e) { //LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e)); } if (result == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed")); } else { return Futures.immediateCheckedFuture(result); } }
From source file:org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadWriteTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { try {/*from w w w . j a v a2 s.com*/ return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent()); } catch (ReadFailedException e) { return Futures.immediateFailedCheckedFuture(e); } }
From source file:org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider.java
private CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> download( final SourceIdentifier sId) { final URL url = availableSources.get(sId); try (final InputStream in = url.openStream()) { final String schemaContent = new String(ByteStreams.toByteArray(in)); final NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource yangSource = new NetconfRemoteSchemaYangSourceProvider.NetconfYangTextSchemaSource( id, sId, Optional.of(schemaContent)); LOG.debug("Source {} downloaded from a yang library's url {}", sId, url); return Futures.immediateCheckedFuture(yangSource); } catch (IOException e) { LOG.warn("Unable to download source {} from a yang library's url {}", sId, url, e); return Futures.immediateFailedCheckedFuture( new SchemaSourceException("Unable to download remote schema for " + sId + " from " + url, e)); }//from w w w . j av a 2 s . c om }
From source file:org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read( final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed")); }//from www. j av a2 s . c o m try { return Futures.immediateCheckedFuture(snapshot.readNode(path)); } catch (final Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e)); } }
From source file:org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read( final YangInstanceIdentifier path) { LOG.debug("Tx: {} Read: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); final DataTreeSnapshot snapshot = stableSnapshot; if (snapshot == null) { return Futures.immediateFailedCheckedFuture(new ReadFailedException("Transaction is closed")); }// w ww.ja v a2 s . c om try { return Futures.immediateCheckedFuture(snapshot.readNode(path)); } catch (Exception e) { LOG.error("Tx: {} Failed Read of {}", getIdentifier(), path, e); return Futures.immediateFailedCheckedFuture(new ReadFailedException("Read failed", e)); } }
From source file:org.opendaylight.yangtools.yang.model.repo.util.InMemorySchemaSourceCache.java
@Override public CheckedFuture<? extends T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) { final T present = cache.getIfPresent(sourceIdentifier); if (present != null) { return Futures.immediateCheckedFuture(present); }//from w w w . j a v a 2 s . c om return Futures.immediateFailedCheckedFuture( new MissingSchemaSourceException("Source not found", sourceIdentifier)); }
From source file:org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Exists: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); try {/* w w w . j a va 2 s. c o m*/ return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent()); } catch (final ReadFailedException e) { return Futures.immediateFailedCheckedFuture(e); } }
From source file:org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { LOG.debug("Tx: {} Exists: {}", getIdentifier(), path); checkNotNull(path, "Path must not be null."); try {/*from ww w. j a v a2 s . c o m*/ return Futures.immediateCheckedFuture(read(path).checkedGet().isPresent()); } catch (ReadFailedException e) { return Futures.immediateFailedCheckedFuture(e); } }
From source file:io.airlift.discovery.client.testing.InMemoryDiscoveryClient.java
@Override public CheckedFuture<Duration, DiscoveryException> announce(Set<ServiceAnnouncement> services) { Preconditions.checkNotNull(services, "services is null"); ImmutableSet.Builder<ServiceDescriptor> builder = ImmutableSet.builder(); for (ServiceAnnouncement service : services) { builder.add(service.toServiceDescriptor(nodeInfo)); }//from ww w. j ava2 s. com announcements.set(builder.build()); return Futures.immediateCheckedFuture(maxAge); }