本文整理汇总了Java中io.vertx.core.CompositeFuture.setHandler方法的典型用法代码示例。如果您正苦于以下问题:Java CompositeFuture.setHandler方法的具体用法?Java CompositeFuture.setHandler怎么用?Java CompositeFuture.setHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.CompositeFuture
的用法示例。
在下文中一共展示了CompositeFuture.setHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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_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)));
}
示例3: should_Represent_failures_and_successes_simultaneously
import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@Test
public void should_Represent_failures_and_successes_simultaneously() {
AtomicBoolean success = new AtomicBoolean();
ArrayList<Collection> loadCalls = new ArrayList<>();
DataLoader<Integer, Integer> evenLoader = idLoaderWithErrors(new DataLoaderOptions(), loadCalls);
Future<Integer> future1 = evenLoader.load(1);
Future<Integer> future2 = evenLoader.load(2);
Future<Integer> future3 = evenLoader.load(3);
Future<Integer> future4 = evenLoader.load(4);
CompositeFuture result = evenLoader.dispatch();
result.setHandler(rh -> success.set(true));
await().untilAtomic(success, is(true));
assertThat(future1.failed(), is(true));
assertThat(future1.cause(), instanceOf(IllegalStateException.class));
assertThat(future2.result(), equalTo(2));
assertThat(future3.failed(), is(true));
assertThat(future4.result(), equalTo(4));
assertThat(loadCalls, equalTo(Collections.singletonList(asList(1, 2, 3, 4))));
}
示例4: should_Resolve_to_empty_list_when_no_keys_supplied
import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@Test
public void should_Resolve_to_empty_list_when_no_keys_supplied() {
AtomicBoolean success = new AtomicBoolean();
CompositeFuture futureEmpty = identityLoader.loadMany(Collections.emptyList());
futureEmpty.setHandler(rh -> {
assertThat(rh.result().size(), is(0));
success.set(rh.succeeded());
});
identityLoader.dispatch();
await().untilAtomic(success, is(true));
assertThat(futureEmpty.list(), empty());
}
示例5: start
import io.vertx.core.CompositeFuture; //导入方法依赖的package包/类
@Override
public void start(Future<Void> startPromise) {
VertxResteasyDeployment deployment = new VertxResteasyDeployment();
deployment.start();
deployment.getProviderFactory().registerProvider(DefaultExceptionMapper.class);
deployment.getProviderFactory().registerProvider(JacksonConfig.class);
if (enableRbac) {
log.info("Enabling RBAC for REST API");
deployment.getProviderFactory().registerProviderInstance(new AuthInterceptor(kubernetes));
} else {
log.info("Disabling authentication and authorization for REST API");
deployment.getProviderFactory().registerProviderInstance(new AllowAllAuthInterceptor());
}
deployment.getRegistry().addSingletonResource(new SwaggerSpecEndpoint());
deployment.getRegistry().addSingletonResource(new HttpAddressService(addressSpaceApi));
deployment.getRegistry().addSingletonResource(new HttpSchemaService());
deployment.getRegistry().addSingletonResource(new HttpAddressSpaceService(addressSpaceApi, kubernetes.getNamespace()));
deployment.getRegistry().addSingletonResource(new HttpHealthService());
deployment.getRegistry().addSingletonResource(new HttpV1RootService());
deployment.getRegistry().addSingletonResource(new HttpRootService());
deployment.getRegistry().addSingletonResource(new HttpAddressRootService(addressSpaceApi));
deployment.getRegistry().addSingletonResource(new OSBCatalogService(addressSpaceApi, kubernetes.getNamespace()));
deployment.getRegistry().addSingletonResource(new OSBProvisioningService(addressSpaceApi, kubernetes.getNamespace()));
deployment.getRegistry().addSingletonResource(new OSBBindingService(addressSpaceApi, kubernetes.getNamespace()));
deployment.getRegistry().addSingletonResource(new OSBLastOperationService(addressSpaceApi, kubernetes.getNamespace()));
VertxRequestHandler requestHandler = new VertxRequestHandler(vertx, deployment);
Future<Void> secureReady = Future.future();
Future<Void> openReady = Future.future();
CompositeFuture readyFuture = CompositeFuture.all(secureReady, openReady);
readyFuture.setHandler(result -> {
if (result.succeeded()) {
startPromise.complete();
} else {
startPromise.fail(result.cause());
}
});
createSecureServer(requestHandler, secureReady);
createOpenServer(requestHandler, openReady);
}