當前位置: 首頁>>代碼示例>>Java>>正文


Java ListenableFuture.isDone方法代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.ListenableFuture.isDone方法的典型用法代碼示例。如果您正苦於以下問題:Java ListenableFuture.isDone方法的具體用法?Java ListenableFuture.isDone怎麽用?Java ListenableFuture.isDone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.util.concurrent.ListenableFuture的用法示例。


在下文中一共展示了ListenableFuture.isDone方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: refresh

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
 * Refreshes the value associated with {@code key}, unless another thread is already doing so.
 * Returns the newly refreshed value associated with {@code key} if it was refreshed inline, or
 * {@code null} if another thread is performing the refresh or if an error occurs during
 * refresh.
 */
@Nullable
V refresh(K key, int hash, CacheLoader<? super K, V> loader, boolean checkTime) {
  final LoadingValueReference<K, V> loadingValueReference =
      insertLoadingValueReference(key, hash, checkTime);
  if (loadingValueReference == null) {
    return null;
  }

  ListenableFuture<V> result = loadAsync(key, hash, loadingValueReference, loader);
  if (result.isDone()) {
    try {
      return Uninterruptibles.getUninterruptibly(result);
    } catch (Throwable t) {
      // don't let refresh exceptions propagate; error was already logged
    }
  }
  return null;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:25,代碼來源:LocalCache.java

示例2: getSerialNumber

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@GET
@Produces("text/plain")
@PermitAll
public Response getSerialNumber() {
    final ListenableFuture<String> masterPassword = encyptionKeyProvider.getMasterPassword();
    if (!masterPassword.isDone()) {
        return Response.status(Response.Status.PRECONDITION_FAILED)
                .entity("Key is not set yet..")
                .build();
    }
    return Response
            .ok(serialNumberService.getPublicIdentifier())
            .build();
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:15,代碼來源:SerialNoResource.java

示例3: getToken

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public Optional<String> getToken() {
        final ListenableFuture<String> masterPassword = encyptionKeyProvider.getMasterPassword();
        if (!masterPassword.isDone()) {
            return Optional.empty();
        }
        final String key = encyptionKeyProvider.getImmediatePassword();
        final String s = key + " meta";
        final ECKey privKey = ECKey.fromPrivate(Sha256Hash.twiceOf(s.getBytes(Charsets.UTF_8)).getBytes());

/*
        @POST
        @Path("/token")
        @Produces(MediaType.APPLICATION_OCTET_STREAM)
        public Response createToken(@QueryParam("timestamp") Long nonce, @QueryParam("signature") String signature) {
*/

//        }
        final long timeStamp = Instant.now().toEpochMilli();
        try {
            final String url = rootPath + "auth/token";
            final HttpResponse<String> token = Unirest.post(url)
                    .queryString("timestamp", timeStamp)
                    .queryString("signature", privKey.signMessage(String.valueOf(timeStamp)))
                    .asString();
            if (token.getStatus() != 200) {
                return Optional.empty();
            }
            return Optional.of(token.getBody());
        } catch (UnirestException e) {
            LOGGER.error("exception from remote service when trying to get token", e);
            return Optional.empty();
        }

    }
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:35,代碼來源:RemoteTokenService.java

示例4: waitForSufficientBalance

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
private void waitForSufficientBalance(Coin amount) {
    // Not enough money in the wallet.
    Coin amountPlusFee = amount.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    // ESTIMATED because we don't really need to wait for confirmation.
    ListenableFuture<Coin> balanceFuture = appKit.wallet().getBalanceFuture(amountPlusFee, Wallet.BalanceType.ESTIMATED);
    if (!balanceFuture.isDone()) {
        System.out.println("Please send " + amountPlusFee.toFriendlyString() +
                " to " + myKey.toAddress(params));
        Futures.getUnchecked(balanceFuture);
    }
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:12,代碼來源:ExamplePaymentChannelClient.java

示例5: jobIsRunning

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
	 * Returns true if the job is actually running in a thread
	 * @param yadaJob
	 * @return
	 */
	public boolean jobIsRunning(Long yadaJobId) {
		ListenableFuture<?> jobHandle = jobHandles.get(yadaJobId);
		if (jobHandle!=null) {
			boolean running = !jobHandle.isDone();
//			if (!running) {
//				jobHandles.remove(yadaJob); // As a side effect, the map is cleaned up
//			}
			return running;
		}
		return false;
	}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:17,代碼來源:YadaJobScheduler.java

示例6: successfulFuture

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@SuppressWarnings("checkstyle:IllegalCatch")
private static boolean successfulFuture(final ListenableFuture<Void> future) {
    if (!future.isDone()) {
        return false;
    }

    try {
        future.get();
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:14,代碼來源:ThreePhaseCommitCohortProxy.java

示例7: executeForInstitutions

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
private void executeForInstitutions(Collection<Institution> insts) throws InterruptedException, ExecutionException
{
	Iterator<ReferencedURL> bi = new ReferencedURLIterator();

	// Asynchronously check a maximum number of URLs at any given time. As
	// they complete, remove them from the working set and fill it back up
	// with more.
	Set<ListenableFuture<ReferencedURL>> workingset = Sets.newHashSetWithExpectedSize(MAX_CONCURRENT_CHECKS);
	while( bi.hasNext() || !workingset.isEmpty() )
	{
		// Remove completed URLs.
		for( Iterator<ListenableFuture<ReferencedURL>> iter = workingset.iterator(); iter.hasNext(); )
		{
			ListenableFuture<ReferencedURL> f = iter.next();
			if( f.isDone() )
			{
				iter.remove();

				ReferencedURL rurl = f.get();
				dao.updateWithTransaction(rurl);

				// Send event if exactly at the warning or disabled level.
				URLEventType eventType = null;
				if( rurl.getTries() == policy.getTriesUntilWarning() )
				{
					eventType = URLEventType.URL_WARNING;
				}
				else if( rurl.getTries() == policy.getTriesUntilDisabled() )
				{
					eventType = URLEventType.URL_DISABLED;
				}

				if( eventType != null )
				{
					// Send event to all institutions
					eventService.publishApplicationEvent(insts, new URLEvent(eventType, rurl.getUrl()));
				}
			}
		}

		// Fill up the working set with maximum allowed.
		while( bi.hasNext() && workingset.size() < MAX_CONCURRENT_CHECKS )
		{
			workingset.add(service.checkUrl(bi.next()));
		}

		// Now sleep for a couple of seconds before trying again, at least
		// some URLs should already be complete.
		Thread.sleep(TimeUnit.SECONDS.toMillis(2));
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:52,代碼來源:CheckURLsScheduledTask.java


注:本文中的com.google.common.util.concurrent.ListenableFuture.isDone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。