本文整理匯總了Java中io.vertx.core.Future.future方法的典型用法代碼示例。如果您正苦於以下問題:Java Future.future方法的具體用法?Java Future.future怎麽用?Java Future.future使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.vertx.core.Future
的用法示例。
在下文中一共展示了Future.future方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: delete
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> delete(SQLConnection connection, String id) {
Future<Void> future = Future.future();
String sql = "DELETE FROM Articles WHERE id = ?";
connection.updateWithParams(sql,
new JsonArray().add(Integer.valueOf(id)),
ar -> {
connection.close();
if (ar.failed()) {
future.fail(ar.cause());
} else {
if (ar.result().getUpdated() == 0) {
future.fail(new NoSuchElementException("Unknown article " + id));
} else {
future.complete();
}
}
}
);
return future;
}
示例2: storage
import io.vertx.core.Future; //導入方法依賴的package包/類
private <E extends Storable> Future<AsyncStorage<E>> storage(Class<E> storable, String index) {
Future<AsyncStorage<E>> future = Future.future();
logger.event("onStorageLoad", STARTUP)
.put("storage", config.getStorage().name())
.put("plugin", storable.getSimpleName())
.put("index", index).send();
new StorageLoader<E>(context)
.withDB(index, index)
.withValue(storable)
.withPlugin(config.getStoragePlugin())
.build((storage) -> {
if (storage.succeeded()) {
future.complete(storage.result());
} else {
logger.log("Failed to load storage " + config.getStoragePlugin().getSimpleName() +
" using index" + index);
future.fail(storage.cause());
}
});
return future;
}
示例3: start
import io.vertx.core.Future; //導入方法依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
Future<String> dbVerticleDeployment = Future.future();
vertx.deployVerticle(new WikiDatabaseVerticle(), dbVerticleDeployment.completer());
dbVerticleDeployment.compose(id -> {
Future<String> httpVerticleDeployment = Future.future();
vertx.deployVerticle(
"io.vertx.guides.wiki.http.HttpServerVerticle",
new DeploymentOptions().setInstances(2),
httpVerticleDeployment.completer());
return httpVerticleDeployment;
}).setHandler(ar -> {
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
}
示例4: deployWebSocketVerticle
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<String> deployWebSocketVerticle(DeploymentOptions options) {
Future<String> future = Future.future();
vertx.deployVerticle(new BittrexRemoteVerticle(), options, res -> {
if (res.succeeded()) {
ws_id = res.result();
System.out.println("WebsocketVerticle Deployment id is: " + res.result());
future.complete();
} else {
System.err.println("WebsocketVerticle Deployment failed: " + res.cause().getMessage());
future.fail(res.cause());
}
});
return future;
}
示例5: importBlocks
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> importBlocks(StorableBlock block) {
Future<Void> future = Future.future();
if (config.isTxImport()) {
listener.onQueueChanged(queue.incrementAndGet());
storage.put(block, done -> {
if (done.succeeded()) {
if (!config.isTxImport()) {
listener.onImported(block.getHash(), block.getNumber());
}
future.complete();
} else {
future.fail(done.cause());
}
listener.onQueueChanged(queue.decrementAndGet());
});
} else {
future.complete();
}
return future;
}
示例6: registerReceiver
import io.vertx.core.Future; //導入方法依賴的package包/類
/**
* Same as {@link #getReceiverRegistrator} but tries to register receiver and returns future with it
* @param <I> Interface
* @param vertx Vertx instance
* @param interfaceType Class for which receiver should be generated
* @param receiver Interface implementation that should be registered
* @return Future that on completion returns successfully registered {@link VxRifaReceiver} and fails otherwise
*/
public static <I> Future<VxRifaReceiver<I>> registerReceiver(Vertx vertx, Class<I> interfaceType, I receiver) {
Future<VxRifaReceiver<I>> future = Future.future();
VxRifaReceiver<I> receiverRegistrator = getReceiverRegistrator(vertx, interfaceType);
receiverRegistrator.registerReceiver(receiver).setHandler(complete -> {
if (complete.succeeded()) {
future.complete(receiverRegistrator);
} else {
future.fail(complete.cause());
}
});
return future;
}
示例7: testDeployInvalidConfig
import io.vertx.core.Future; //導入方法依賴的package包/類
@Test
public void testDeployInvalidConfig(TestContext testContext) throws Exception {
Future<Void> future = Future.future();
future.setHandler(testContext.asyncAssertFailure(res -> {
Assert.assertFalse(vtxDeployer.isVertxSetup());
Assert.assertTrue("Non-existing configuration", Exception.class.isInstance(res));
}));
vtxDeployer.setup("sample/non-existing.json", future);
}
示例8: createTempDir
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> createTempDir(JsonObject metadata) {
Future future = Future.future();
String dir = metadata.getString("baseDir");
vertx.fileSystem().mkdirs(dir, ar -> {
if (ar.failed()) {
log.error("Impossible to create temp directory {}: {}", dir, ar.cause().getMessage());
future.fail(ar.cause());
} else {
future.complete();
}
});
return future;
}
示例9: close
import io.vertx.core.Future; //導入方法依賴的package包/類
void close(Handler<AsyncResult<Void>> completionHandler) {
synchronized (vertx) {
if (--refCount == 0) {
Future<Void> f1 = Future.future();
Future<Void> f2 = Future.future();
if (completionHandler != null) {
CompositeFuture.all(f1, f2).<Void>map(f -> null).setHandler(completionHandler);
}
if (emf != null) {
vertx.executeBlocking(future -> {
emf.close();
future.complete();
}, f2.completer());
} else {
f2.complete();
}
try {
if (exec != null) {
exec.shutdown();
}
if (map != null) {
map.remove(name);
if (map.isEmpty()) {
map.close();
}
}
f1.complete();
} catch (Throwable t) {
f1.fail(t);
}
} else {
if (completionHandler != null) {
completionHandler.handle(Future.succeededFuture());
}
}
}
}
示例10: start
import io.vertx.core.Future; //導入方法依賴的package包/類
@Override
public void start(Future<Void> fut) throws Exception {
LOG.info("Starting KafkaStreams and Webserver");
Future runtimeVerticleCompleter = Future.future();
vertx.deployVerticle(runtimeVerticle, runtimeVerticleCompleter.completer());
// Create a router object.
Router router = Router.router(vertx);
addRouteForMultiValuedKVQueries(router);
addRouteForScalarKVQueries(router);
addRouteForWindowQueries(router);
addRouteForKVCountQueries(router);
addRouteForSessionQueries(router);
Future serverListener = Future.future();
int port = vertx
.createHttpServer(serverOptions)
.requestHandler(router::accept)
.listen(serverListener.completer())
.actualPort();
CompositeFuture.all(runtimeVerticleCompleter, serverListener).setHandler(handler -> {
if (handler.succeeded()) {
LOG.info("Started KafkaStreams and Webserver, listening on port " + port);
fut.complete();
} else {
LOG.error("Failure during startup", handler.cause());
fut.fail(handler.cause());
}
});
}
示例11: tearDown
import io.vertx.core.Future; //導入方法依賴的package包/類
@AfterClass
public static void tearDown(TestContext testContext) throws Exception {
Future<Void> future = Future.future();
future.setHandler(testContext.asyncAssertSuccess(res -> {
Assert.assertFalse(vtxDeployer.isVertxSetup());
}));
vtxDeployer.teardown(future);
}
示例12: prepareDatabase
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> prepareDatabase() {
Future<Void> future = Future.future();
dbClient = JDBCClient.createShared(vertx, new JsonObject() // <1>
.put("url", "jdbc:hsqldb:file:db/wiki") // <2>
.put("driver_class", "org.hsqldb.jdbcDriver") // <3>
.put("max_pool_size", 30)); // <4>
dbClient.getConnection(ar -> { // <5>
if (ar.failed()) {
LOGGER.error("Could not open a database connection", ar.cause());
future.fail(ar.cause()); // <6>
} else {
SQLConnection connection = ar.result(); // <7>
connection.execute(SQL_CREATE_PAGES_TABLE, create -> {
connection.close(); // <8>
if (create.failed()) {
LOGGER.error("Database preparation error", create.cause());
future.fail(create.cause());
} else {
future.complete(); // <9>
}
});
}
});
return future;
}
示例13: connect
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<SQLConnection> connect() {
Future<SQLConnection> future = Future.future();
jdbc.getConnection(ar ->
future.handle(ar.map(c ->
c.setOptions(new SQLOptions().setAutoGeneratedKeys(true))
)
)
);
return future;
}
示例14: toArrayFuture
import io.vertx.core.Future; //導入方法依賴的package包/類
static <T> Future<JsonArray> toArrayFuture(
final String pojo,
final CompletableFuture<List<T>> completableFuture
) {
final Future<JsonArray> future = Future.future();
Fn.safeSemi(null == completableFuture, null,
() -> future.complete(new JsonArray()),
() -> completableFuture.thenAcceptAsync((item) -> Fn.safeSemi(
null == item, null,
() -> future.complete(new JsonArray()),
() -> future.complete(To.toArray(item, pojo))
)));
return future;
}
示例15: createHttpServer
import io.vertx.core.Future; //導入方法依賴的package包/類
private Future<Void> createHttpServer(JsonObject config, Router router) {
Future<Void> future = Future.future();
vertx
.createHttpServer()
.requestHandler(router::accept)
.listen(
config.getInteger("HTTP_PORT", 8080),
res -> future.handle(res.mapEmpty())
);
return future;
}