本文整理匯總了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;
}
示例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();
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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));
}
}