当前位置: 首页>>代码示例>>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;未经允许,请勿转载。