当前位置: 首页>>代码示例>>Java>>正文


Java CompositeFuture.join方法代码示例

本文整理汇总了Java中io.vertx.core.CompositeFuture.join方法的典型用法代码示例。如果您正苦于以下问题:Java CompositeFuture.join方法的具体用法?Java CompositeFuture.join怎么用?Java CompositeFuture.join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.CompositeFuture的用法示例。


在下文中一共展示了CompositeFuture.join方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dispatch

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
/**
 * Dispatches the queued load requests to the batch execution function and returns a composite future of the result.
 * <p>
 * If batching is disabled, or there are no queued requests, then a succeeded composite future is returned.
 *
 * @return the composite future of the queued load requests
 */
public CompositeFuture dispatch() {
    if (!loaderOptions.batchingEnabled() || loaderQueue.size() == 0) {
        return CompositeFuture.join(Collections.emptyList());
    }
    CompositeFuture batch = batchLoadFunction.load(loaderQueue.keySet());
    dispatchedQueues.put(batch, new LinkedHashMap<>(loaderQueue));
    batch.setHandler(rh -> {
        AtomicInteger index = new AtomicInteger(0);
        dispatchedQueues.get(batch).forEach((key, future) -> {
            if (batch.succeeded(index.get())) {
                future.complete(batch.resultAt(index.get()));
            } else {
                future.fail(batch.cause(index.get()));
            }
            index.incrementAndGet();
        });
        dispatchedQueues.remove(batch);
    });
    loaderQueue.clear();
    return batch;
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:29,代码来源:DataLoader.java

示例2: should_Build_a_really_really_simple_data_loader

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@Test
public void should_Build_a_really_really_simple_data_loader() {
    AtomicBoolean success = new AtomicBoolean();
    DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keys ->
        CompositeFuture.join(keys.stream()
                .map(Future::succeededFuture)
                .collect(Collectors.toCollection(ArrayList::new))));

    Future<Integer> future1 = identityLoader.load(1);
    future1.setHandler(rh -> {
        assertThat(rh.result(), equalTo(1));
        success.set(rh.succeeded());
    });
    identityLoader.dispatch();
    await().untilAtomic(success, is(true));
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:17,代码来源:DataLoaderTest.java

示例3: should_Support_loading_multiple_keys_in_one_call

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@Test
public void should_Support_loading_multiple_keys_in_one_call() {
    AtomicBoolean success = new AtomicBoolean();
    DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keys ->
            CompositeFuture.join(keys.stream()
                    .map(Future::succeededFuture)
                    .collect(Collectors.toCollection(ArrayList::new))));

    CompositeFuture futureAll = identityLoader.loadMany(asList(1, 2));
    futureAll.setHandler(rh -> {
        assertThat(rh.result().size(), is(2));
        success.set(rh.succeeded());
    });
    identityLoader.dispatch();
    await().untilAtomic(success, is(true));
    assertThat(futureAll.list(), equalTo(asList(1, 2)));
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:18,代码来源:DataLoaderTest.java

示例4: idLoader

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <K, V> DataLoader<K, V> idLoader(DataLoaderOptions options, List<Collection> loadCalls) {
    return new DataLoader<>(keys -> {
        loadCalls.add(new ArrayList(keys));
        List<Future> futures = keys.stream().map(Future::succeededFuture).collect(Collectors.toList());
        return CompositeFuture.join(futures);
    }, options);
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:9,代码来源:DataLoaderTest.java

示例5: idLoaderAllErrors

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static <K, V> DataLoader<K, V> idLoaderAllErrors(
        DataLoaderOptions options, List<Collection> loadCalls) {
    return new DataLoader<>(keys -> {
        loadCalls.add(new ArrayList(keys));
        List<Future> futures = keys.stream()
                .map(key -> Future.failedFuture(new IllegalStateException("Error")))
                .collect(Collectors.toList());
        return CompositeFuture.join(futures);
    }, options);
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:12,代码来源:DataLoaderTest.java

示例6: idLoaderWithErrors

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static DataLoader<Integer, Integer> idLoaderWithErrors(
        DataLoaderOptions options, List<Collection> loadCalls) {
    return new DataLoader<>(keys -> {
        loadCalls.add(new ArrayList(keys));
        List<Future> futures = keys.stream()
                .map(key -> key % 2 == 0 ? Future.succeededFuture(key) :
                        Future.failedFuture(new IllegalStateException("Error")))
                .collect(Collectors.toList());
        return CompositeFuture.join(futures);
    }, options);
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:13,代码来源:DataLoaderTest.java

示例7: closeAllClients

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
/**
 * Close all SQL clients stored in the connection pool.
 */
public static void closeAllClients() {
  @SuppressWarnings("rawtypes")
  List<Future> list = new ArrayList<>(connectionPool.size());
  // copy of values() because closeClient will delete them from connectionPool
  for (PostgresClient client : connectionPool.values().toArray(new PostgresClient [0])) {
    Future<Object> future = Future.future();
    list.add(future);
    client.closeClient(f -> future.complete());
  }

  CompositeFuture.join(list);
}
 
开发者ID:folio-org,项目名称:raml-module-builder,代码行数:16,代码来源:PostgresClient.java

示例8: loadMany

import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
/**
 * Requests to load the list of data provided by the specified keys asynchronously, and returns a composite future
 * of the resulting values.
 * <p>
 * If batching is enabled (the default), you'll have to call {@link DataLoader#dispatch()} at a later stage to
 * start batch execution. If you forget this call the future will never be completed (unless already completed,
 * and returned from cache).
 *
 * @param keys the list of keys to load
 * @return the composite future of the list of values
 */
public CompositeFuture loadMany(List<K> keys) {
    return CompositeFuture.join(keys.stream().map(this::load).collect(Collectors.toList()));
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:15,代码来源:DataLoader.java


注:本文中的io.vertx.core.CompositeFuture.join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。