List of usage examples for com.google.common.util.concurrent Futures allAsList
@Beta @CheckReturnValue public static <V> ListenableFuture<List<V>> allAsList( Iterable<? extends ListenableFuture<? extends V>> futures)
From source file:org.opendaylight.netvirt.fibmanager.VrfEntryListener.java
public void cleanUpDpnForVpn(final BigInteger dpnId, final long vpnId, final String rd, final FutureCallback<List<Void>> callback) { LOG.trace("cleanUpDpnForVpn: Remove dpn {} for vpn {} : cleanUpDpnForVpn", dpnId, rd); InstanceIdentifier<VrfTables> id = buildVrfId(rd); final VpnInstanceOpDataEntry vpnInstance = getVpnInstance(rd); final Optional<VrfTables> vrfTable = FibUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, id); if (vrfTable.isPresent()) { DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance(); dataStoreCoordinator.enqueueJob("FIB-" + vpnId + "-" + dpnId.toString(), () -> { List<ListenableFuture<Void>> futures = new ArrayList<>(); synchronized (vpnInstance.getVpnInstanceName().intern()) { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); for (final VrfEntry vrfEntry : vrfTable.get().getVrfEntry()) { /* Handle subnet routes here */ SubnetRoute subnetRoute = vrfEntry.getAugmentation(SubnetRoute.class); if (subnetRoute != null) { LOG.trace("Cleaning subnetroute {} on dpn {} for vpn {} : cleanUpDpnForVpn", vrfEntry.getDestPrefix(), dpnId, rd); makeConnectedRoute(dpnId, vpnId, vrfEntry, rd, null, NwConstants.DEL_FLOW, tx); java.util.Optional.ofNullable(vrfEntry.getRoutePaths()).ifPresent(routePaths -> { routePaths.stream().forEach(routePath -> { makeLFibTableEntry(dpnId, routePath.getLabel(), null, DEFAULT_FIB_FLOW_PRIORITY, NwConstants.DEL_FLOW, tx); LOG.trace( "cleanUpDpnForVpn: Released subnetroute label {} " + "for rd {} prefix {}", routePath.getLabel(), rd, vrfEntry.getDestPrefix()); });//from www . j av a2 s . com }); continue; } // ping responder for router interfaces RouterInterface routerInt = vrfEntry.getAugmentation(RouterInterface.class); if (routerInt != null) { LOG.trace("Router augmented vrfentry found for rd:{}, uuid:{}, ip:{}, mac:{}", rd, routerInt.getUuid(), routerInt.getIpAddress(), routerInt.getMacAddress()); installRouterFibEntry(vrfEntry, dpnId, vpnId, routerInt.getUuid(), routerInt.getIpAddress(), new MacAddress(routerInt.getMacAddress()), NwConstants.DEL_FLOW); continue; } // Passing null as we don't know the dpn // to which prefix is attached at this point List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnInstance.getVpnId(), vrfEntry.getDestPrefix()); String vpnName = FibUtil.getVpnNameFromId(dataBroker, vpnInstance.getVpnId()); Optional<Routes> extraRouteOptional; //Is this fib route an extra route? If yes, get the nexthop which would be //an adjacency in the vpn if (usedRds != null && !usedRds.isEmpty()) { if (usedRds.size() > 1) { LOG.error("The extra route prefix is still present in some DPNs"); return futures; } else { extraRouteOptional = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRds.get(0), vrfEntry.getDestPrefix()); } } else { extraRouteOptional = Optional.absent(); } deleteRemoteRoute(null, dpnId, vpnId, vrfTable.get().getKey(), vrfEntry, extraRouteOptional, tx); } futures.add(tx.submit()); if (callback != null) { ListenableFuture<List<Void>> listenableFuture = Futures.allAsList(futures); Futures.addCallback(listenableFuture, callback); } } return futures; }); } }
From source file:com.google.sha1coin.core.Wallet.java
/** * A wallet app should call this from time to time if key rotation is enabled in order to let the wallet craft and * send transactions needed to re-organise coins internally. A good time to call this would be after receiving coins * for an unencrypted wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and * just want to know if some maintenance needs doing, call this method with doSend set to false and look at the * returned list of transactions./* w w w . j av a 2 s.com*/ * * @param aesKey the users password, if any. * @param andSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. */ public ListenableFuture<List<Transaction>> maybeDoMaintenance(@Nullable KeyParameter aesKey, boolean andSend) { List<Transaction> txns; lock.lock(); try { txns = maybeRotateKeys(aesKey); if (!andSend) return Futures.immediateFuture(txns); } finally { lock.unlock(); } checkState(!lock.isHeldByCurrentThread()); ArrayList<ListenableFuture<Transaction>> futures = new ArrayList<ListenableFuture<Transaction>>( txns.size()); TransactionBroadcaster broadcaster = vTransactionBroadcaster; for (Transaction tx : txns) { try { final ListenableFuture<Transaction> future = broadcaster.broadcastTransaction(tx); futures.add(future); Futures.addCallback(future, new FutureCallback<Transaction>() { @Override public void onSuccess(Transaction transaction) { log.info("Successfully broadcast key rotation tx: {}", transaction); } @Override public void onFailure(Throwable throwable) { log.error("Failed to broadcast key rotation tx", throwable); } }); } catch (Exception e) { log.error("Failed to broadcast rekey tx", e); } } return Futures.allAsList(futures); }
From source file:org.neoscoinj.core.Wallet.java
/** * A wallet app should call this from time to time in order to let the wallet craft and send transactions needed * to re-organise coins internally. A good time to call this would be after receiving coins for an unencrypted * wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and just want to know * if some maintenance needs doing, call this method with andSend set to false and look at the returned list of * transactions. Maintenance might also include internal changes that involve some processing or work but * which don't require making transactions - these will happen automatically unless the password is required * in which case an exception will be thrown. * * @param aesKey the users password, if any. * @param signAndSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. * @throws org.neoscoinj.wallet.DeterministicUpgradeRequiresPassword if key rotation requires the users password. *//*from w ww. j a v a 2 s .c om*/ public ListenableFuture<List<Transaction>> doMaintenance(@Nullable KeyParameter aesKey, boolean signAndSend) throws DeterministicUpgradeRequiresPassword { List<Transaction> txns; lock.lock(); keychainLock.lock(); try { txns = maybeRotateKeys(aesKey, signAndSend); if (!signAndSend) return Futures.immediateFuture(txns); } finally { keychainLock.unlock(); lock.unlock(); } checkState(!lock.isHeldByCurrentThread()); ArrayList<ListenableFuture<Transaction>> futures = new ArrayList<ListenableFuture<Transaction>>( txns.size()); TransactionBroadcaster broadcaster = vTransactionBroadcaster; for (Transaction tx : txns) { try { final ListenableFuture<Transaction> future = broadcaster.broadcastTransaction(tx); futures.add(future); Futures.addCallback(future, new FutureCallback<Transaction>() { @Override public void onSuccess(Transaction transaction) { log.info("Successfully broadcast key rotation tx: {}", transaction); } @Override public void onFailure(Throwable throwable) { log.error("Failed to broadcast key rotation tx", throwable); } }); } catch (Exception e) { log.error("Failed to broadcast rekey tx", e); } } return Futures.allAsList(futures); }
From source file:org.bitcoinj.core.Wallet.java
/** * A wallet app should call this from time to time in order to let the wallet craft and send transactions needed * to re-organise coins internally. A good time to call this would be after receiving coins for an unencrypted * wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and just want to know * if some maintenance needs doing, call this method with andSend set to false and look at the returned list of * transactions. Maintenance might also include internal changes that involve some processing or work but * which don't require making transactions - these will happen automatically unless the password is required * in which case an exception will be thrown. * * @param aesKey the users password, if any. * @param signAndSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. * @throws org.bitcoinj.wallet.DeterministicUpgradeRequiresPassword if key rotation requires the users password. *///from www . ja v a 2 s. com public ListenableFuture<List<Transaction>> doMaintenance(@Nullable KeyParameter aesKey, boolean signAndSend) throws DeterministicUpgradeRequiresPassword { List<Transaction> txns; lock.lock(); keychainLock.lock(); try { txns = maybeRotateKeys(aesKey, signAndSend); if (!signAndSend) return Futures.immediateFuture(txns); } finally { keychainLock.unlock(); lock.unlock(); } checkState(!lock.isHeldByCurrentThread()); ArrayList<ListenableFuture<Transaction>> futures = new ArrayList<ListenableFuture<Transaction>>( txns.size()); TransactionBroadcaster broadcaster = vTransactionBroadcaster; for (Transaction tx : txns) { try { final ListenableFuture<Transaction> future = broadcaster.broadcastTransaction(tx).future(); futures.add(future); Futures.addCallback(future, new FutureCallback<Transaction>() { @Override public void onSuccess(Transaction transaction) { log.info("Successfully broadcast key rotation tx: {}", transaction); } @Override public void onFailure(Throwable throwable) { log.error("Failed to broadcast key rotation tx", throwable); } }); } catch (Exception e) { log.error("Failed to broadcast rekey tx", e); } } return Futures.allAsList(futures); }
From source file:org.litecoinj.wallet.Wallet.java
/** * A wallet app should call this from time to time in order to let the wallet craft and send transactions needed * to re-organise coins internally. A good time to call this would be after receiving coins for an unencrypted * wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and just want to know * if some maintenance needs doing, call this method with andSend set to false and look at the returned list of * transactions. Maintenance might also include internal changes that involve some processing or work but * which don't require making transactions - these will happen automatically unless the password is required * in which case an exception will be thrown. * * @param aesKey the users password, if any. * @param signAndSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. * @throws org.litecoinj.wallet.DeterministicUpgradeRequiresPassword if key rotation requires the users password. *//*from ww w .j a v a 2 s . c o m*/ public ListenableFuture<List<Transaction>> doMaintenance(@Nullable KeyParameter aesKey, boolean signAndSend) throws DeterministicUpgradeRequiresPassword { List<Transaction> txns; lock.lock(); keyChainGroupLock.lock(); try { txns = maybeRotateKeys(aesKey, signAndSend); if (!signAndSend) return Futures.immediateFuture(txns); } finally { keyChainGroupLock.unlock(); lock.unlock(); } checkState(!lock.isHeldByCurrentThread()); ArrayList<ListenableFuture<Transaction>> futures = new ArrayList<>(txns.size()); TransactionBroadcaster broadcaster = vTransactionBroadcaster; for (Transaction tx : txns) { try { final ListenableFuture<Transaction> future = broadcaster.broadcastTransaction(tx).future(); futures.add(future); Futures.addCallback(future, new FutureCallback<Transaction>() { @Override public void onSuccess(Transaction transaction) { log.info("Successfully broadcast key rotation tx: {}", transaction); } @Override public void onFailure(Throwable throwable) { log.error("Failed to broadcast key rotation tx", throwable); } }); } catch (Exception e) { log.error("Failed to broadcast rekey tx", e); } } return Futures.allAsList(futures); }
From source file:org.bitcoinj_extra.wallet.Wallet.java
/** * A wallet app should call this from time to time in order to let the wallet craft and send transactions needed * to re-organise coins internally. A good time to call this would be after receiving coins for an unencrypted * wallet, or after sending money for an encrypted wallet. If you have an encrypted wallet and just want to know * if some maintenance needs doing, call this method with andSend set to false and look at the returned list of * transactions. Maintenance might also include internal changes that involve some processing or work but * which don't require making transactions - these will happen automatically unless the password is required * in which case an exception will be thrown. * * @param aesKey the users password, if any. * @param signAndSend if true, send the transactions via the tx broadcaster and return them, if false just return them. * @return A list of transactions that the wallet just made/will make for internal maintenance. Might be empty. * @throws org.bitcoinj_extra.wallet.DeterministicUpgradeRequiresPassword if key rotation requires the users password. *//*from ww w . j av a2 s .c o m*/ public ListenableFuture<List<Transaction>> doMaintenance(@Nullable KeyParameter aesKey, boolean signAndSend) throws DeterministicUpgradeRequiresPassword { List<Transaction> txns; lock.lock(); keyChainGroupLock.lock(); try { txns = maybeRotateKeys(aesKey, signAndSend); if (!signAndSend) return Futures.immediateFuture(txns); } finally { keyChainGroupLock.unlock(); lock.unlock(); } checkState(!lock.isHeldByCurrentThread()); ArrayList<ListenableFuture<Transaction>> futures = new ArrayList<ListenableFuture<Transaction>>( txns.size()); TransactionBroadcaster broadcaster = vTransactionBroadcaster; for (Transaction tx : txns) { try { final ListenableFuture<Transaction> future = broadcaster.broadcastTransaction(tx).future(); futures.add(future); Futures.addCallback(future, new FutureCallback<Transaction>() { @Override public void onSuccess(Transaction transaction) { log.info("Successfully broadcast key rotation tx: {}", transaction); } @Override public void onFailure(Throwable throwable) { log.error("Failed to broadcast key rotation tx", throwable); } }); } catch (Exception e) { log.error("Failed to broadcast rekey tx", e); } } return Futures.allAsList(futures); }