Example usage for com.google.common.util.concurrent ListenableFuture get

List of usage examples for com.google.common.util.concurrent ListenableFuture get

Introduction

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

Prototype

V get() throws InterruptedException, ExecutionException;

Source Link

Document

Waits if necessary for the computation to complete, and then retrieves its result.

Usage

From source file:com.github.nethad.clustermeister.provisioning.torque.TorqueJPPFTestSetup.java

private void startNodes() {

    //        torqueNodeManager.deployResources();
    TorqueNodeConfiguration nodeConfiguration = TorqueNodeConfiguration.configurationForNode(driverIpAddress, 1,
            new LinkedList<File>());
    for (int i = 0; i < NUMBER_OF_NODES; i++) {
        ListenableFuture<Void> node = torqueNodeManager.addNode(nodeConfiguration);
        try {//w  w  w  . j  av a  2  s.c  o  m
            node.get();
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        } catch (ExecutionException ex) {
            ex.printStackTrace();
        }
    }
    //      nodes = new ArrayList<ListenableFuture<? extends Node>>();
    //         nodes.add(torqueNodeManager.addNode(nodeConfiguration));
}

From source file:c5db.webadmin.StatusServlet.java

private ImmutableMap<Long, NodeInfo> getNodes() throws InterruptedException, ExecutionException {
    DiscoveryModule discoveryModule = service.getDiscoveryModule();
    if (discoveryModule == null) {
        return null;
    }//from  w w w .jav  a2s .c o m

    ListenableFuture<ImmutableMap<Long, NodeInfo>> nodeFuture = discoveryModule.getState();
    return nodeFuture.get();
}

From source file:org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvokerImpl.java

@Override
public void invoke(TransactCommand command) {
    TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
    command.execute(tb);/*from w  w w  .j av  a2 s. c o  m*/
    ListenableFuture<List<OperationResult>> result = tb.execute();
    LOG.debug("TransactInvokerImpl: command: {}, tb: {}", command, tb);
    try {
        List<OperationResult> got = result.get();
        LOG.debug("OVSDB transaction result: {}", got);
    } catch (Exception e) {
        LOG.warn("Transact execution exception: ", e);
    }
}

From source file:com.google.vertcoin.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {/*from  www  .  ja  v  a  2 s . co m*/
        System.out.println("Payment Request");
        System.out.println("Amount: " + session.getValue().doubleValue() / 100000 + "mVTC");
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.name);
            if (session.pkiVerificationData.orgName != null)
                System.out.println("Pki-Verified Org: " + session.pkiVerificationData.orgName);
        }
        final Wallet.SendRequest req = session.getSendRequest();
        if (password != null) {
            if (!wallet.checkPassword(password)) {
                System.err.println("Password is incorrect.");
                return;
            }
            req.aesKey = wallet.getKeyCrypter().deriveKey(password);
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.startAndWait();
            peers.broadcastTransaction(req.tx).get();
        } else {
            PaymentSession.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentRequestException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err
                .println("Insufficient funds: have " + Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.airlift.drift.client.stats.JmxMethodInvocationStat.java

@Override
public void recordResult(long startTime, ListenableFuture<Object> result) {
    result.addListener(() -> {//from w w  w  .  j  ava 2  s . c om
        time.add(nanosSince(startTime));
        try {
            result.get();
            successes.update(1);
        } catch (Throwable throwable) {
            failures.update(1);
        }
    }, directExecutor());
}

From source file:com.woollysammoth.nubitj.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {/* w  w w .ja  v a2  s  .  c  o  m*/
        System.out.println("Payment Request");
        System.out.println("Amount: " + session.getValue().doubleValue() / 100000 + "mBTC");
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.name);
            if (session.pkiVerificationData.orgName != null)
                System.out.println("Pki-Verified Org: " + session.pkiVerificationData.orgName);
            System.out.println("PKI data verified by: " + session.pkiVerificationData.rootAuthorityName);
        }
        final Wallet.SendRequest req = session.getSendRequest();
        if (password != null) {
            if (!wallet.checkPassword(password)) {
                System.err.println("Password is incorrect.");
                return;
            }
            req.aesKey = wallet.getKeyCrypter().deriveKey(password);
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.startAndWait();
            peers.broadcastTransaction(req.tx).get();
        } else {
            PaymentSession.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentRequestException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err.println("Insufficient funds: have " + Utils.nubitValueToFriendlyString(wallet.getBalance()));
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.zetacoin.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {//from   w  ww . ja  va 2s.  co m
        System.out.println("Payment Request");
        System.out.println("Amount: " + session.getValue().doubleValue() / 100000 + "mBTC");
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.name);
            if (session.pkiVerificationData.orgName != null)
                System.out.println("Pki-Verified Org: " + session.pkiVerificationData.orgName);
        }
        final Wallet.SendRequest req = session.getSendRequest();
        if (password != null) {
            if (!wallet.checkPassword(password)) {
                System.err.println("Password is incorrect.");
                return;
            }
            req.aesKey = wallet.getKeyCrypter().deriveKey(password);
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.startAndWait();
            peers.broadcastTransaction(req.tx).get();
        } else {
            PaymentSession.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentRequestException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err
                .println("Insufficient funds: have " + Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.MaybeMaintenanceFragment.java

private boolean maintenanceRecommended() {
    try {//  w  w  w  .ja  va 2  s. c o  m
        final ListenableFuture<List<Transaction>> result = application.getWallet().doMaintenance(null, false);
        return !result.get().isEmpty();
    } catch (final DeterministicUpgradeRequiresPassword x) {
        return true;
    } catch (final Exception x) {
        throw new RuntimeException(x);
    }
}

From source file:com.google.leafcoin.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {//from w  w  w .jav a  2 s .  c om
        System.out.println("Payment Request");
        System.out.println("Amount: " + session.getValue().doubleValue() / 100000 + "mLEAF");
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.name);
            if (session.pkiVerificationData.orgName != null)
                System.out.println("Pki-Verified Org: " + session.pkiVerificationData.orgName);
            System.out.println("PKI data verified by: " + session.pkiVerificationData.rootAuthorityName);
        }
        final Wallet.SendRequest req = session.getSendRequest();
        if (password != null) {
            if (!wallet.checkPassword(password)) {
                System.err.println("Password is incorrect.");
                return;
            }
            req.aesKey = wallet.getKeyCrypter().deriveKey(password);
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.startAndWait();
            peers.broadcastTransaction(req.tx).get();
        } else {
            PaymentSession.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentRequestException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err
                .println("Insufficient funds: have " + Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.spartancoin.tools.WalletTool.java

private static void send(PaymentSession session) {
    try {/*from ww w  .  j a va  2  s . co m*/
        System.out.println("Payment Request");
        System.out.println("Amount: " + session.getValue().doubleValue() / 100000 + "mBTC");
        System.out.println("Date: " + session.getDate());
        System.out.println("Memo: " + session.getMemo());
        if (session.pkiVerificationData != null) {
            System.out.println("Pki-Verified Name: " + session.pkiVerificationData.name);
            if (session.pkiVerificationData.orgName != null)
                System.out.println("Pki-Verified Org: " + session.pkiVerificationData.orgName);
            System.out.println("PKI data verified by: " + session.pkiVerificationData.rootAuthorityName);
        }
        final Wallet.SendRequest req = session.getSendRequest();
        if (password != null) {
            if (!wallet.checkPassword(password)) {
                System.err.println("Password is incorrect.");
                return;
            }
            req.aesKey = wallet.getKeyCrypter().deriveKey(password);
        }
        wallet.completeTx(req); // may throw InsufficientMoneyException.
        if (options.has("offline")) {
            wallet.commitTx(req.tx);
            return;
        }
        setup();
        // No refund address specified, no user-specified memo field.
        ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
        if (future == null) {
            // No payment_url for submission so, broadcast and wait.
            peers.startAndWait();
            peers.broadcastTransaction(req.tx).get();
        } else {
            PaymentSession.Ack ack = future.get();
            wallet.commitTx(req.tx);
            System.out.println("Memo from server: " + ack.getMemo());
        }
    } catch (PaymentRequestException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (VerificationException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (ExecutionException e) {
        System.err.println("Failed to send payment " + e.getMessage());
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Invalid payment " + e.getMessage());
        System.exit(1);
    } catch (InterruptedException e1) {
        // Ignore.
    } catch (InsufficientMoneyException e) {
        System.err
                .println("Insufficient funds: have " + Utils.bitcoinValueToFriendlyString(wallet.getBalance()));
    } catch (BlockStoreException e) {
        throw new RuntimeException(e);
    }
}