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


Java ListenableFuture.addListener方法代碼示例

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


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

示例1: testListener

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Test()
public void testListener() throws Exception {
    final Path keyfile = Paths.get("./junit/etc/minebox/randomkey.txt");
    try {
        Assert.assertFalse(Files.exists(keyfile));
        final LazyEncyptionKeyProvider key = new LazyEncyptionKeyProvider("./junit/etc/minebox/randomkey.txt");
        final ListenableFuture<String> masterPassword = key.getMasterPassword();
        Assert.assertFalse(masterPassword.isDone());
        final CountDownLatch count = new CountDownLatch(1);
        masterPassword.addListener(count::countDown, Executors.newSingleThreadExecutor());
        Files.write(keyfile, PWBYTES);
        count.await();
        Assert.assertTrue(masterPassword.isDone());
        Assert.assertEquals(PW, key.getImmediatePassword());
    } finally {
        Files.delete(keyfile);
    }
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:19,代碼來源:EncyptionKeyProviderTest.java

示例2: recordResult

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Override
public void recordResult(long startTime, ListenableFuture<Object> result)
{
    result.addListener(
            () -> {
                time.add(nanosSince(startTime));
                try {
                    result.get();
                    successes.update(1);
                }
                catch (Throwable throwable) {
                    failures.update(1);
                }
            },
            directExecutor());
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:17,代碼來源:JmxMethodInvocationStat.java

示例3: recordResult

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Override
public void recordResult(long startTime, ListenableFuture<Object> result)
{
    invocations.incrementAndGet();
    result.addListener(
            () -> {
                lastStartTime.set(startTime);
                try {
                    result.get();
                    successes.incrementAndGet();
                }
                catch (Throwable throwable) {
                    failures.incrementAndGet();
                }
            },
            directExecutor());
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:18,代碼來源:TestingMethodInvocationStat.java

示例4: loadAsync

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
ListenableFuture<V> loadAsync(
    final K key,
    final int hash,
    final LoadingValueReference<K, V> loadingValueReference,
    CacheLoader<? super K, V> loader) {
  final ListenableFuture<V> loadingFuture = loadingValueReference.loadFuture(key, loader);
  loadingFuture.addListener(
      new Runnable() {
        @Override
        public void run() {
          try {
            getAndRecordStats(key, hash, loadingValueReference, loadingFuture);
          } catch (Throwable t) {
            logger.log(Level.WARNING, "Exception thrown during refresh", t);
            loadingValueReference.setException(t);
          }
        }
      },
      directExecutor());
  return loadingFuture;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:22,代碼來源:LocalCache.java

示例5: uploadBlobAsync

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@VisibleForTesting
ListenableFuture<Void> uploadBlobAsync(Chunker chunker)
    /* throws IOException */ {
  Digest digest = checkNotNull(chunker.digest());

  synchronized (lock) {
    checkState(!isShutdown, "Must not call uploadBlobs after shutdown.");

    ListenableFuture<Void> uploadResult = uploadsInProgress.get(digest);
    if (uploadResult == null) {
      uploadResult = SettableFuture.create();
      uploadResult.addListener(
          () -> {
            synchronized (lock) {
              uploadsInProgress.remove(digest);
            }
          },
          MoreExecutors.directExecutor());
      startAsyncUploadWithRetry(
          chunker, retrier.newBackoff(), (SettableFuture<Void>) uploadResult);
      uploadsInProgress.put(digest, uploadResult);
    }
    return uploadResult;
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel-buildfarm,代碼行數:26,代碼來源:ByteStreamUploader.java

示例6: add

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
 * Add a Future delegate
 */
public synchronized void add(final ListenableFuture<V> f) {
    if (isCancelled() || isDone()) return;

    f.addListener(new Runnable() {
        public void run() {
            futureCompleted(f);
        }
    },  MoreExecutors.sameThreadExecutor());
    futures.add(f);
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:14,代碼來源:AnyFuture.java

示例7: invoke

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
@Override
public ListenableFuture<Object> invoke(InvokeRequest request, MethodInvoker next)
{
    requestCount.getAndIncrement();
    ListenableFuture<Object> result = next.invoke(request);
    result.addListener(replyCount::getAndIncrement, directExecutor());
    return result;
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:9,代碼來源:TestFilter.java

示例8: MockFutureListener

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
public MockFutureListener(ListenableFuture<?> future) {
  this.countDownLatch = new CountDownLatch(1);
  this.future = future;

  future.addListener(this, directExecutor());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:7,代碼來源:MockFutureListener.java

示例9: addInternalStatsReplyListener

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
/**
 * Append a listener to receive an OFStatsReply and update the 
 * internal OFSwitch data structures.
 * 
 * This presently taps into the following stats request 
 * messages to listen for the corresponding reply:
 * -- OFTableFeaturesStatsRequest
 * 
 * Extend this to tap into and update other OFStatsType messages.
 * 
 * @param future
 * @param request
 * @return
 */
private <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> addInternalStatsReplyListener(final ListenableFuture<List<REPLY>> future, OFStatsRequest<REPLY> request) {
	switch (request.getStatsType()) {
	case TABLE_FEATURES:
		/* case YOUR_CASE_HERE */
		future.addListener(new Runnable() {
			/*
			 * We know the reply will be a list of OFStatsReply.
			 */
			@SuppressWarnings("unchecked")
			@Override
			public void run() {
				/*
				 * The OFConnection handles REPLY_MORE for us in the case there
				 * are multiple OFStatsReply messages with the same XID.
				 */
				try {
					List<? extends OFStatsReply> replies = future.get();
					if (!replies.isEmpty()) {
						/*
						 * By checking only the 0th element, we assume all others are the same type.
						 * TODO If not, what then?
						 */
						switch (replies.get(0).getStatsType()) {
						case TABLE_FEATURES:
							processOFTableFeatures((List<OFTableFeaturesStatsReply>) future.get());
							break;
							/* case YOUR_CASE_HERE */
						default:
							throw new Exception("Received an invalid OFStatsReply of " 
									+ replies.get(0).getStatsType().toString() + ". Expected TABLE_FEATURES.");
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}, MoreExecutors.sameThreadExecutor()); /* No need for another thread. */
	default:
		break;
	}
	return future; /* either unmodified or with an additional listener */
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:57,代碼來源:OFSwitch.java

示例10: addComplete

import com.google.common.util.concurrent.ListenableFuture; //導入方法依賴的package包/類
private ListenableFuture<Void> addComplete(final ListenableFuture<Void> future) {
    future.addListener(this::complete, MoreExecutors.directExecutor());
    return future;
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:5,代碼來源:ClientTransactionCommitCohort.java


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