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


Java CompositeFuture.setHandler方法代码示例

本文整理汇总了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;
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:29,代码来源:DataLoader.java

示例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)));
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:18,代码来源:DataLoaderTest.java

示例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))));
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:23,代码来源:DataLoaderTest.java

示例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());
}
 
开发者ID:engagingspaces,项目名称:vertx-dataloader,代码行数:13,代码来源:DataLoaderTest.java

示例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);
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:47,代码来源:HTTPServer.java


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