List of usage examples for com.google.common.util.concurrent Futures makeChecked
@GwtIncompatible("TODO") @CheckReturnValue public static <V, X extends Exception> CheckedFuture<V, X> makeChecked(ListenableFuture<V> future, Function<? super Exception, X> mapper)
From source file:org.opendaylight.infrautils.utils.concurrent.FluentFutures2.java
/** * Converts Guava's (new) FluentFuture to its (old) CheckedFuture. * This is useful while migrating APIs.//www . ja v a 2 s. c o m * * <p>The implementation just uses {@link Futures#makeChecked(ListenableFuture, com.google.common.base.Function)}, * so this is pure syntactic sugar - making it easier to remember and find: you have a FluentFuture and you find * this with convenience conversion methods - like we have for other types in this package. * * @deprecated Replace {@link CheckedFuture} usages in your code by * {@link FluentFuture} (or {@link CompletionStage}) */ @Deprecated // TODO remove this method when all of its usages have been removed and its unnecessary public static <V, E extends Exception> CheckedFuture<V, E> toChecked(FluentFuture<V> future, Function<? super Exception, E> mapper) { return Futures.makeChecked(future, mapper::apply); }
From source file:org.opendaylight.controller.cluster.databroker.ClientBackedReadTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read( final YangInstanceIdentifier path) { return Futures.makeChecked(delegate().read(path), ReadFailedException.MAPPER); }
From source file:org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapter.ShardedDOMDataBrokerDelegatingReadTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) { return Futures.makeChecked( delegateTx.read(LegacyShardedDOMDataBrokerAdapterUtils.translateDataStoreType(store), path), ReadFailedException.MAPPER); }
From source file:org.opendaylight.controller.cluster.databroker.ClientBackedReadTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) { return Futures.makeChecked(delegate().exists(path), ReadFailedException.MAPPER); }
From source file:org.opendaylight.netconf.topology.pipeline.tx.ProxyReadOnlyTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) { final Future<Optional<NormalizedNodeMessage>> future = delegate.read(store, path); final SettableFuture<Optional<NormalizedNode<?, ?>>> settableFuture = SettableFuture.create(); final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> checkedFuture = Futures .makeChecked(settableFuture, new Function<Exception, ReadFailedException>() { @Nullable/*from ww w .j av a 2 s. c o m*/ @Override public ReadFailedException apply(Exception cause) { return new ReadFailedException("Read from transaction failed", cause); } }); future.onComplete(new OnComplete<Optional<NormalizedNodeMessage>>() { @Override public void onComplete(Throwable throwable, Optional<NormalizedNodeMessage> normalizedNodeMessage) throws Throwable { if (throwable == null) { if (normalizedNodeMessage.isPresent()) { settableFuture.set(normalizedNodeMessage .transform(new Function<NormalizedNodeMessage, NormalizedNode<?, ?>>() { @Nullable @Override public NormalizedNode<?, ?> apply(NormalizedNodeMessage input) { return input.getNode(); } })); } else { settableFuture.set(Optional.absent()); } } else { settableFuture.setException(throwable); } } }, actorSystem.dispatcher()); return checkedFuture; }
From source file:org.opendaylight.controller.md.sal.dom.broker.impl.legacy.sharded.adapter.ShardedDOMDataBrokerDelegatingReadTransaction.java
@Override public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store, final YangInstanceIdentifier path) { return Futures.makeChecked( delegateTx.exists(LegacyShardedDOMDataBrokerAdapterUtils.translateDataStoreType(store), path), ReadFailedException.MAPPER); }
From source file:org.onos.yangtools.yang.parser.repo.SettableSchemaProvider.java
@Override public CheckedFuture<T, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) { return Futures.makeChecked(future, new Function<Exception, SchemaSourceException>() { @Nullable//from w ww.j av a2s.c o m @Override public SchemaSourceException apply(@Nullable final Exception input) { return new SchemaSourceException("Failed", input); } }); }
From source file:org.opendaylight.netconf.topology.singleton.impl.tx.NetconfReadOnlyTransaction.java
@Override public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) { LOG.trace("{}: Read {} via NETCONF: {}", id, store, path); final Future<Optional<NormalizedNodeMessage>> future = delegate.read(store, path); final SettableFuture<Optional<NormalizedNode<?, ?>>> settableFuture = SettableFuture.create(); final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> checkedFuture; checkedFuture = Futures.makeChecked(settableFuture, new Function<Exception, ReadFailedException>() { @Nullable/* w w w .j a va 2s. co m*/ @Override public ReadFailedException apply(Exception cause) { return new ReadFailedException("Read from transaction failed", cause); } }); future.onComplete(new OnComplete<Optional<NormalizedNodeMessage>>() { @Override public void onComplete(final Throwable throwable, final Optional<NormalizedNodeMessage> normalizedNodeMessage) throws Throwable { if (throwable == null) { if (normalizedNodeMessage.isPresent()) { settableFuture.set(normalizedNodeMessage .transform(new Function<NormalizedNodeMessage, NormalizedNode<?, ?>>() { @Nullable @Override public NormalizedNode<?, ?> apply(final NormalizedNodeMessage input) { return input.getNode(); } })); } else { settableFuture.set(Optional.absent()); } } else { settableFuture.setException(throwable); } } }, actorSystem.dispatcher()); return checkedFuture; }
From source file:org.opendaylight.netconf.topology.pipeline.tx.ProxyWriteOnlyTransaction.java
@Override public CheckedFuture<Void, TransactionCommitFailedException> submit() { final Future<Void> submit = delegate.submit(); final SettableFuture<Void> settableFuture = SettableFuture.create(); final CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = Futures .makeChecked(settableFuture, new Function<Exception, TransactionCommitFailedException>() { @Nullable// w w w .j a v a 2 s . c om @Override public TransactionCommitFailedException apply(Exception input) { return new TransactionCommitFailedException("Transaction commit failed", input); } }); submit.onComplete(new OnComplete<Void>() { @Override public void onComplete(Throwable throwable, Void aVoid) throws Throwable { if (throwable == null) { settableFuture.set(aVoid); } else { settableFuture.setException(throwable); } } }, actorSystem.dispatcher()); return checkedFuture; }
From source file:org.onos.yangtools.yang.model.repo.util.AbstractSchemaRepository.java
private static final <T extends SchemaSourceRepresentation> CheckedFuture<T, SchemaSourceException> fetchSource( final SourceIdentifier id, final Iterator<AbstractSchemaSourceRegistration<?>> it) { final AbstractSchemaSourceRegistration<?> reg = it.next(); @SuppressWarnings("unchecked") final CheckedFuture<? extends T, SchemaSourceException> f = ((SchemaSourceProvider<T>) reg.getProvider()) .getSource(id);/*from w ww . j av a 2s . com*/ return Futures.makeChecked(Futures.withFallback(f, new FutureFallback<T>() { @Override public ListenableFuture<T> create(final Throwable t) throws SchemaSourceException { LOG.debug("Failed to acquire source from {}", reg, t); if (it.hasNext()) { return fetchSource(id, it); } throw new MissingSchemaSourceException("All available providers exhausted", id, t); } }), FETCH_MAPPER); }