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