本文整理汇总了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));
}
}