本文整理汇总了Java中io.vertx.core.CompositeFuture类的典型用法代码示例。如果您正苦于以下问题:Java CompositeFuture类的具体用法?Java CompositeFuture怎么用?Java CompositeFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompositeFuture类属于io.vertx.core包,在下文中一共展示了CompositeFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchOneByConditionWithMultipleMatchesShouldFail
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Test
public void fetchOneByConditionWithMultipleMatchesShouldFail() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Future<Integer> insertFuture1 = Future.future();
Future<Integer> insertFuture2 = Future.future();
Something someNewObject = createSomething();
dao.insertReturningPrimaryAsync(someNewObject,insertFuture1);
dao.insertReturningPrimaryAsync(createSomething().setSomehugenumber(someNewObject.getSomehugenumber()),insertFuture2);
CompositeFuture.all(insertFuture1,insertFuture2).
setHandler(consumeOrFailHandler(v->{
dao.fetchOneAsync(Tables.SOMETHING.SOMEHUGENUMBER.eq(someNewObject.getSomehugenumber()),h->{
Assert.assertNotNull(h.cause());
//cursor fetched more than one row
Assert.assertEquals(TooManyRowsException.class, h.cause().getClass());
dao.deleteExecAsync(Tables.SOMETHING.SOMEHUGENUMBER.eq(someNewObject.getSomehugenumber()),countdownLatchHandler(latch));
});
}));
await(latch);
}
示例2: createSomeDataIfNone
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private Future<SQLConnection> createSomeDataIfNone(SQLConnection connection) {
Future<SQLConnection> future = Future.future();
connection.query("SELECT * FROM Articles", select -> {
if (select.failed()) {
future.fail(select.cause());
} else {
if (select.result().getResults().isEmpty()) {
Article article1 = new Article("Fallacies of distributed computing",
"https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing");
Article article2 = new Article("Reactive Manifesto",
"https://www.reactivemanifesto.org/");
Future<Article> insertion1 = insert(connection, article1, false);
Future<Article> insertion2 = insert(connection, article2, false);
CompositeFuture.all(insertion1, insertion2)
.setHandler(r -> future.handle(r.map(connection)));
} else {
future.complete(connection);
}
}
});
return future;
}
示例3: fetchByConditionWithMultipleMatchesShouldSucceed
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Test
public void fetchByConditionWithMultipleMatchesShouldSucceed() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Future<Integer> insertFuture1 = Future.future();
Future<Integer> insertFuture2 = Future.future();
Something someNewObject = createSomething();
dao.insertReturningPrimaryAsync(someNewObject,insertFuture1);
dao.insertReturningPrimaryAsync(createSomething().setSomehugenumber(someNewObject.getSomehugenumber()),insertFuture2);
CompositeFuture.all(insertFuture1, insertFuture2).
setHandler(consumeOrFailHandler(v -> {
dao.fetchAsync(Tables.SOMETHING.SOMEHUGENUMBER.eq(someNewObject.getSomehugenumber()), h -> {
Assert.assertNotNull(h.result());
//cursor fetched more than one row
Assert.assertEquals(2, h.result().size());
dao.deleteExecAsync(Tables.SOMETHING.SOMEHUGENUMBER.eq(someNewObject.getSomehugenumber()), countdownLatchHandler(latch));
});
}));
await(latch);
}
示例4: generate
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
public void generate(Message<JsonObject> message) {
JsonObject metadata = message.body();
String build = metadata.getString("build", "maven");
String language = metadata.getString("language", "java");
//Act as a activation flags in .gitignore
metadata.put(build, true);
metadata.put(language, true);
String baseDir = metadata.getString("baseDir");
CompositeFuture.all(
generateFile(metadata, baseDir, BUILD.get(build)),
generateFile(metadata, baseDir, LANGUAGES.get(language)),
generateFile(metadata, baseDir, ".gitignore"),
generateFile(metadata, baseDir, ".editorconfig")
).setHandler(ar -> {
if (ar.failed()) {
log.error("Impossible to generate project {} : {}", metadata, ar.cause().getMessage());
message.fail(500, ar.cause().getMessage());
} else {
message.reply(null);
}
});
}
示例5: startInstances
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private void startInstances(Future<Void> future, RealmContext context) {
List<Future> futures = new ArrayList<>();
for (InstanceSettings instance : context.instances()) {
Future deploy = Future.future();
futures.add(deploy);
context.handler(() -> new InstanceHandler(new InstanceContext(context, instance))).setHandler((done) -> {
if (done.succeeded()) {
deploy.complete();
} else {
context.onInstanceFailed(instance.getName(), done.cause());
deploy.fail(done.cause());
}
});
}
CompositeFuture.all(futures).setHandler(done -> {
if (done.succeeded()) {
future.complete();
} else {
future.fail(done.cause());
}
});
}
示例6: testWithFailedCommands
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Test
public void testWithFailedCommands(TestContext tc) {
breaker = CircuitBreaker.create("some-circuit-breaker", vertx);
Async async = tc.async();
Future<Void> command1 = breaker.execute(commandThatFails());
Future<Void> command2 = breaker.execute(commandThatWorks());
Future<Void> command3 = breaker.execute(commandThatWorks());
Future<Void> command4 = breaker.execute(commandThatFails());
CompositeFuture.join(command1, command2, command3, command4)
.setHandler(ar -> {
assertThat(metrics())
.contains("name", "some-circuit-breaker")
.contains("state", CircuitBreakerState.CLOSED.name())
.contains("totalErrorCount", 2) // Failure + Timeout + Exception
.contains("totalSuccessCount", 2)
.contains("totalTimeoutCount", 0)
.contains("totalExceptionCount", 0)
.contains("totalFailureCount", 2)
.contains("totalOperationCount", 4)
.contains("totalSuccessPercentage", 50)
.contains("totalErrorPercentage", 50);
async.complete();
});
}
示例7: testEviction
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Test
public void testEviction(TestContext tc) {
breaker = CircuitBreaker.create("some-circuit-breaker", vertx,
new CircuitBreakerOptions().setMetricsRollingWindow(10));
Async async = tc.async();
int count = 1000;
List<Future> list = new ArrayList<>();
for (int i = 0; i < count; i++) {
list.add(breaker.execute(commandThatWorks()));
}
CompositeFuture.all(list)
.setHandler(ar -> {
assertThat(ar).succeeded();
assertThat(metrics().getInteger("totalOperationCount")).isEqualTo(1000);
assertThat(metrics().getInteger("rollingOperationCount")).isLessThan(1000);
async.complete();
});
}
示例8: doSubCmd
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private void doSubCmd(ApiDiscovery discovery, List<ApiDefinition> definitions,
ApiSubCmd subCmd,
JsonObject jsonObject, Future<JsonObject> complete) {
List<Future> futures = new ArrayList<>();
for (ApiDefinition definition : definitions) {
Future<Void> future = Future.future();
futures.add(future);
subCmd.handle(definition, jsonObject);
discovery.publish(definition, ar -> {
if (ar.succeeded()) {
future.complete();
} else {
future.fail(ar.cause());
}
});
}
CompositeFuture.all(futures)
.setHandler(ar -> {
if (ar.succeeded()) {
complete.complete(succeedResult());
} else {
complete.fail(ar.cause());
}
});
}
示例9: deleteByName
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private void deleteByName(ApiDiscovery discovery, List<String> names,
Future<JsonObject> complete) {
List<Future> futures = new ArrayList<>();
for (String name : names) {
Future<Void> future = Future.future();
futures.add(future);
discovery.unpublish(name, ar -> {
if (ar.succeeded()) {
future.complete();
} else {
future.fail(ar.cause());
}
});
}
CompositeFuture.all(futures)
.setHandler(ar -> {
if (ar.succeeded()) {
complete.complete(succeedResult());
} else {
complete.fail(ar.cause());
}
});
}
示例10: unregisterAllServices
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private synchronized void unregisterAllServices(Future<Void> completed) {
List<Future> list = new ArrayList<>();
imports.forEach(svc -> {
Future<Void> unreg = Future.future();
svc.unregister(publisher, unreg);
list.add(unreg);
});
CompositeFuture.all(list).setHandler(x -> {
if (x.failed()) {
completed.fail(x.cause());
} else {
completed.complete();
}
});
}
示例11: restartModules
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
public void restartModules(Handler<ExtendedAsyncResult<Void>> fut) {
deploymentStore.getAll(res1 -> {
if (res1.failed()) {
fut.handle(new Failure<>(res1.getType(), res1.cause()));
} else {
List<Future> futures = new LinkedList<>();
for (DeploymentDescriptor dd : res1.result()) {
Future<DeploymentDescriptor> f = Future.future();
addAndDeploy1(dd, f::handle);
futures.add(f);
}
CompositeFuture.all(futures).setHandler(res2 -> {
if (res2.failed()) {
fut.handle(new Failure<>(INTERNAL, res2.cause()));
} else {
fut.handle(new Success<>());
}
});
}
});
}
示例12: getKeys2
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private void getKeys2(String val, Handler<ExtendedAsyncResult<Collection<String>>> fut) {
Collection<String> result = new TreeSet<>();
if (val == null || val.isEmpty()) {
fut.handle(new Success<>(result));
} else {
KeyList keys = Json.decodeValue(val, KeyList.class);
List<Future> futures = new LinkedList<>();
for (String k : keys.keys) {
Future<Void> f = Future.future();
list.get(k, res -> {
if (res.failed()) {
f.handle(Future.failedFuture(res.cause()));
} else {
String v = res.result();
if (v != null) {
result.add(k);
}
f.handle(Future.succeededFuture());
}
});
futures.add(f);
}
CompositeFuture.all(futures).setHandler(res -> {
if (res.failed()) {
fut.handle(new Failure<>(INTERNAL, res.cause()));
} else {
fut.handle(new Success<>(result));
}
});
}
}
示例13: unregisterAllServices
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
private synchronized void unregisterAllServices(Future<Void> done) {
List<Future> list = new ArrayList<>();
new HashSet<>(registrations).forEach(reg -> {
Future<Void> unreg = Future.future();
publisher.unpublish(reg.record().getRegistration(), unreg.completer());
});
registrations.clear();
CompositeFuture.all(list).setHandler(x -> {
if (x.failed()) {
done.fail(x.cause());
} else {
done.complete();
}
});
}
示例14: close
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Override
public void close(Handler<Void> completionHandler) {
List<Future> list = new ArrayList<>();
for (Record record : records) {
publisher.unpublish(record.getRegistration(),
v -> list.add(v.succeeded() ? Future.succeededFuture() : Future.failedFuture(v.cause())));
}
CompositeFuture.all(list).setHandler(ar -> {
if (ar.succeeded()) {
LOGGER.info("Successfully closed the service importer " + this);
} else {
LOGGER.error("A failure has been caught while stopping " + this, ar.cause());
}
if (completionHandler != null) {
completionHandler.handle(null);
}
}
);
}
示例15: start
import io.vertx.core.CompositeFuture; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
DeploymentOptionsParser.parseVerticleDeploymentOptionsJsonFile();
// We can safely deploy Command, EventStore, and Query in parallel.
// Facade must be the last one.
Future<Void> startEventStoreFuture = startVerticle(this.vertx, Verticle.EventStore);
Future<Void> startCommandFuture = startVerticle(this.vertx, Verticle.Command);
Future<Void> startQueryFuture = startVerticle(this.vertx, Verticle.Query);
CompositeFuture.all(startCommandFuture, startEventStoreFuture, startQueryFuture).setHandler(ar -> {
if (ar.succeeded()) {
startFuture.setHandler(startVerticle(this.vertx, Verticle.Facade).completer());
} else {
startFuture.fail(ar.cause());
}}
);
}