List of usage examples for com.google.common.util.concurrent Futures getUnchecked
@GwtIncompatible("TODO") public static <V> V getUnchecked(Future<V> future)
From source file:com.facebook.buck.core.build.engine.impl.CachingBuildEngine.java
@Override public int getNumRulesToBuild(Iterable<BuildRule> rules) { Set<BuildRule> seen = Sets.newConcurrentHashSet(); ImmutableList.Builder<ListenableFuture<?>> results = ImmutableList.builder(); for (BuildRule rule : rules) { if (seen.add(rule)) { results.add(walkRule(rule, seen)); }/* w w w. ja v a 2s. c o m*/ } Futures.getUnchecked(Futures.allAsList(results.build())); return seen.size(); }
From source file:org.litecoinj.tools.WalletTool.java
private static void rotate() throws BlockStoreException { setup();/*from w ww.j a va 2 s. c o m*/ peers.start(); // Set a key rotation time and possibly broadcast the resulting maintenance transactions. long rotationTimeSecs = Utils.currentTimeSeconds(); if (options.has(dateFlag)) { rotationTimeSecs = options.valueOf(dateFlag).getTime() / 1000; } else if (options.has(unixtimeFlag)) { rotationTimeSecs = options.valueOf(unixtimeFlag); } log.info("Setting wallet key rotation time to {}", rotationTimeSecs); wallet.setKeyRotationTime(rotationTimeSecs); KeyParameter aesKey = null; if (wallet.isEncrypted()) { aesKey = passwordToKey(true); if (aesKey == null) return; } Futures.getUnchecked(wallet.doMaintenance(aesKey, true)); }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
@Override public void onEnableAutoSync(ContactListFilter filter) { // Turn on auto-sync ContentResolver.setMasterSyncAutomatically(true); // This should be OK (won't block) because this only happens after a user action final List<AccountInfo> accountInfos = Futures.getUnchecked(mWritableAccountsFuture); // Also enable Contacts sync final List<AccountWithDataSet> accounts = AccountInfo.extractAccounts(accountInfos); final List<Account> syncableAccounts = filter.getSyncableAccounts(accounts); if (syncableAccounts != null && syncableAccounts.size() > 0) { for (Account account : syncableAccounts) { ContentResolver.setSyncAutomatically(new Account(account.name, account.type), ContactsContract.AUTHORITY, true); }//from ww w . j a v a 2 s . c o m } mAlertContainer.setVisibility(View.GONE); }
From source file:com.palantir.atlasdb.keyvalue.impl.TieredKeyValueService.java
@Override public void dropTables(Set<String> tableNames) { Map<KeyValueService, Set<String>> tableNamesPerDelegate = Maps.newHashMapWithExpectedSize(2); for (String tableName : tableNames) { Set<String> splitTableNames; // always place in primary if (tableNamesPerDelegate.containsKey(primary)) { splitTableNames = tableNamesPerDelegate.get(primary); } else {// w w w .j ava 2s. c o m splitTableNames = Sets.newHashSet(); } splitTableNames.add(tableName); tableNamesPerDelegate.put(primary, splitTableNames); if (!isNotTiered(tableName)) { // if tiered also place in secondary if (tableNamesPerDelegate.containsKey(secondary)) { splitTableNames = tableNamesPerDelegate.get(secondary); } else { splitTableNames = Sets.newHashSet(); } splitTableNames.add(tableName); tableNamesPerDelegate.put(secondary, splitTableNames); } } List<Future<?>> futures = Lists.newArrayListWithExpectedSize(2); for (final Entry<KeyValueService, Set<String>> tableNamesPerKVS : tableNamesPerDelegate.entrySet()) { futures.add(executor.submit(new Runnable() { @Override public void run() { tableNamesPerKVS.getKey().dropTables(tableNamesPerKVS.getValue()); } })); } for (Future<?> future : futures) { Futures.getUnchecked(future); } }
From source file:org.bitcoinj.tools.WalletTool.java
private static void rotate() throws BlockStoreException { setup();// ww w . ja v a 2s . c o m peerGroup.start(); // Set a key rotation time and possibly broadcast the resulting maintenance transactions. long rotationTimeSecs = Utils.currentTimeSeconds(); if (options.has(dateFlag)) { rotationTimeSecs = options.valueOf(dateFlag).getTime() / 1000; } else if (options.has(unixtimeFlag)) { rotationTimeSecs = options.valueOf(unixtimeFlag); } log.info("Setting wallet key rotation time to {}", rotationTimeSecs); wallet.setKeyRotationTime(rotationTimeSecs); KeyParameter aesKey = null; if (wallet.isEncrypted()) { aesKey = passwordToKey(true); if (aesKey == null) return; } Futures.getUnchecked(wallet.doMaintenance(aesKey, true)); }
From source file:com.palantir.atlasdb.cleaner.Scrubber.java
/** * @return number of cells read from _scrub table *///from w ww .j a v a 2 s . c o m private int scrubSomeCells(SortedMap<Long, Multimap<String, Cell>> scrubTimestampToTableNameToCell, final TransactionManager txManager, long maxScrubTimestamp) { // Don't call expensive toString() if trace logging is off if (log.isTraceEnabled()) { log.trace("Attempting to scrub cells: " + scrubTimestampToTableNameToCell); } if (log.isInfoEnabled()) { int numCells = 0; Set<String> tables = Sets.newHashSet(); for (Multimap<String, Cell> v : scrubTimestampToTableNameToCell.values()) { tables.addAll(v.keySet()); numCells += v.size(); } log.info("Attempting to scrub " + numCells + " cells from tables " + tables); } if (scrubTimestampToTableNameToCell.size() == 0) { return 0; // No cells left to scrub } Multimap<Long, Cell> toRemoveFromScrubQueue = HashMultimap.create(); int numCellsReadFromScrubTable = 0; List<Future<Void>> scrubFutures = Lists.newArrayList(); for (Map.Entry<Long, Multimap<String, Cell>> entry : scrubTimestampToTableNameToCell.entrySet()) { final long scrubTimestamp = entry.getKey(); final Multimap<String, Cell> tableNameToCell = entry.getValue(); numCellsReadFromScrubTable += tableNameToCell.size(); long commitTimestamp = getCommitTimestampRollBackIfNecessary(scrubTimestamp, tableNameToCell); if (commitTimestamp >= maxScrubTimestamp) { // We cannot scrub this yet because not all transactions can read this value. continue; } else if (commitTimestamp != TransactionConstants.FAILED_COMMIT_TS) { // This is CRITICAL; don't scrub if the hard delete transaction didn't actually finish // (we still remove it from the _scrub table with the call to markCellsAsScrubbed though), // or else we could cause permanent data loss if the hard delete transaction failed after // queuing cells to scrub but before successfully committing for (final List<Entry<String, Cell>> batch : Iterables.partition(tableNameToCell.entries(), batchSizeSupplier.get())) { final Multimap<String, Cell> batchMultimap = HashMultimap.create(); for (Entry<String, Cell> e : batch) { batchMultimap.put(e.getKey(), e.getValue()); } scrubFutures.add(exec.submit(new Callable<Void>() { @Override public Void call() throws Exception { scrubCells(txManager, batchMultimap, scrubTimestamp, aggressiveScrub ? TransactionType.AGGRESSIVE_HARD_DELETE : TransactionType.HARD_DELETE); return null; } })); } } toRemoveFromScrubQueue.putAll(scrubTimestamp, tableNameToCell.values()); } for (Future<Void> future : scrubFutures) { Futures.getUnchecked(future); } Multimap<Cell, Long> cellToScrubTimestamp = HashMultimap.create(); scrubberStore.markCellsAsScrubbed(Multimaps.invertFrom(toRemoveFromScrubQueue, cellToScrubTimestamp), batchSizeSupplier.get()); if (log.isTraceEnabled()) { log.trace("Finished scrubbing cells: " + scrubTimestampToTableNameToCell); } if (log.isInfoEnabled()) { Set<String> tables = Sets.newHashSet(); for (Multimap<String, Cell> v : scrubTimestampToTableNameToCell.values()) { tables.addAll(v.keySet()); } long minTimestamp = Collections.min(scrubTimestampToTableNameToCell.keySet()); long maxTimestamp = Collections.max(scrubTimestampToTableNameToCell.keySet()); log.info("Finished scrubbing " + numCellsReadFromScrubTable + " cells at " + scrubTimestampToTableNameToCell.size() + " timestamps (" + minTimestamp + "..." + maxTimestamp + ") from tables " + tables); } return numCellsReadFromScrubTable; }
From source file:org.onosproject.store.flow.impl.ECFlowRuleStore.java
@Override public FlowRuleEvent removeFlowRule(FlowEntry rule) { final DeviceId deviceId = rule.deviceId(); NodeId master = mastershipService.getMasterFor(deviceId); if (Objects.equals(local, master)) { // bypass and handle it locally return removeFlowRuleInternal(rule); }/*from ww w. j a v a 2s.co m*/ if (master == null) { log.warn("Failed to removeFlowRule: No master for {}", deviceId); // TODO: revisit if this should be null (="no-op") or Exception return null; } log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId); return Futures.getUnchecked(clusterCommunicator.sendAndReceive(rule, REMOVE_FLOW_ENTRY, serializer::encode, serializer::decode, master)); }
From source file:com.spotify.futures.FuturesExtra.java
/** * Get the value of a completed future.// w ww. ja va 2 s . c o m * * @param future a completed future. * @return the value of the future if it has one. * @throws IllegalStateException if the future is not completed. * @throws com.google.common.util.concurrent.UncheckedExecutionException if the future has failed */ public static <T> T getCompleted(ListenableFuture<T> future) { checkCompleted(future); return Futures.getUnchecked(future); }
From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java
/** * Request sync for the Google accounts (not include Google+ accounts) specified by the given * filter./*w ww . j a va2s . com*/ */ private void syncContacts(ContactListFilter filter) { if (filter == null) { return; } final Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); final List<AccountWithDataSet> accounts = AccountInfo .extractAccounts(Futures.getUnchecked(mWritableAccountsFuture)); final List<Account> syncableAccounts = filter.getSyncableAccounts(accounts); if (syncableAccounts != null && syncableAccounts.size() > 0) { for (Account account : syncableAccounts) { // We can prioritize Contacts sync if sync is not initialized yet. if (!SyncUtil.isSyncStatusPendingOrActive(account) || SyncUtil.isUnsyncableGoogleAccount(account)) { ContentResolver.requestSync(account, ContactsContract.AUTHORITY, bundle); } } } }
From source file:org.jclouds.openstack.swift.v1.blobstore.RegionScopedSwiftBlobStore.java
@Beta protected String putMultipartBlob(String container, Blob blob, PutOptions overrides, ListeningExecutorService executor) { ArrayList<ListenableFuture<MultipartPart>> parts = new ArrayList<ListenableFuture<MultipartPart>>(); long contentLength = checkNotNull(blob.getMetadata().getContentMetadata().getContentLength(), "must provide content-length to use multi-part upload"); MultipartUploadSlicingAlgorithm algorithm = new MultipartUploadSlicingAlgorithm( getMinimumMultipartPartSize(), getMaximumMultipartPartSize(), getMaximumNumberOfParts()); long partSize = algorithm.calculateChunkSize(contentLength); MultipartUpload mpu = initiateMultipartUpload(container, blob.getMetadata(), partSize, overrides); int partNumber = 0; for (Payload payload : slicer.slice(blob.getPayload(), partSize)) { BlobUploader b = new BlobUploader(mpu, partNumber++, payload); parts.add(executor.submit(b));/*from w ww . j a v a 2 s. c o m*/ } return completeMultipartUpload(mpu, Futures.getUnchecked(Futures.allAsList(parts))); }