Example usage for com.google.common.util.concurrent Futures immediateFailedCheckedFuture

List of usage examples for com.google.common.util.concurrent Futures immediateFailedCheckedFuture

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Futures immediateFailedCheckedFuture.

Prototype

@GwtIncompatible("TODO")
@CheckReturnValue
public static <V, X extends Exception> CheckedFuture<V, X> immediateFailedCheckedFuture(X exception) 

Source Link

Document

Returns a CheckedFuture which has an exception set immediately upon construction.

Usage

From source file:com.google.gwtorm.server.AbstractAccess.java

public CheckedFuture<E, OrmException> getAsync(K key) {
    try {//from w  w  w  . ja v  a 2  s  .c o m
        return Futures.immediateCheckedFuture(get(key));
    } catch (OrmException e) {
        return Futures.immediateFailedCheckedFuture(e);
    }
}

From source file:org.opendaylight.aaa.authz.srv.AuthzReadOnlyTransaction.java

@Override
public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
        LogicalDatastoreType logicalDatastoreType, YangInstanceIdentifier yangInstanceIdentifier) {

    if (AuthzServiceImpl.isAuthorized(logicalDatastoreType, yangInstanceIdentifier, ActionType.Read)) {
        return ro.read(logicalDatastoreType, yangInstanceIdentifier);
    }//from  ww  w.  j a  v  a2s .c  om
    ReadFailedException e = new ReadFailedException("Authorization Failed");
    return Futures.immediateFailedCheckedFuture(e);
}

From source file:org.opendaylight.aaa.authz.srv.AuthzReadOnlyTransaction.java

@Override
public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType logicalDatastoreType,
        YangInstanceIdentifier yangInstanceIdentifier) {

    if (AuthzServiceImpl.isAuthorized(ActionType.Exists)) {
        return ro.exists(logicalDatastoreType, yangInstanceIdentifier);
    }//from w  w  w . j a va2s  .c  o m
    ReadFailedException e = new ReadFailedException("Authorization Failed");
    return Futures.immediateFailedCheckedFuture(e);
}

From source file:org.opendaylight.controller.sal.core.spi.data.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 {//  ww  w.  j  av a2 s  .co  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:com.facebook.buck.util.network.ThriftScribeLogger.java

@Override
public ListenableFuture<Void> log(final String category, final Iterable<String> lines) {
    synchronized (executorService) {
        if (executorService.isShutdown()) {
            String errorMessage = String.format(
                    "%s will not accept any more log calls because it has already been closed.", getClass());
            LOG.warn(errorMessage);//from  ww w.  ja  va2 s .  c  o m
            return Futures.immediateFailedCheckedFuture(new IllegalStateException(errorMessage));
        }
    }

    return executorService.submit(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            sendViaThrift(category, lines);
            return null;
        }
    });
}

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 {//ww  w.ja v  a 2s.co  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.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  w  ww.j a v a 2s.c o  m

    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.aaa.authz.srv.AuthzDataReadWriteTransaction.java

@Override
public CheckedFuture<Void, TransactionCommitFailedException> submit() {
    if (AuthzServiceImpl.isAuthorized(ActionType.Submit)) {
        return domDataReadWriteTransaction.submit();
    }//  w w  w.  ja  v  a2 s  .  c  om
    TransactionCommitFailedException e = new TransactionCommitFailedException("Unauthorized User");
    return Futures.immediateFailedCheckedFuture(e);
}

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"));
    }/*ww  w . jav  a2 s.co  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"));
    }/*from   w  w w  .  j av  a  2  s.  c  o  m*/

    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));
    }
}