本文整理匯總了Java中io.vertx.core.Future類的典型用法代碼示例。如果您正苦於以下問題:Java Future類的具體用法?Java Future怎麽用?Java Future使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Future類屬於io.vertx.core包,在下文中一共展示了Future類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import io.vertx.core.Future; //導入依賴的package包/類
/**
* @see io.vertx.core.AbstractVerticle#start(io.vertx.core.Future)
*/
@Override
public void start(final Future<Void> startFuture) throws Exception {
this.logger.trace("Client for SFDC Platform Events starting");
this.router = Router.router(this.getVertx());
// Load config and verticles and signal back that we are done
final Future<Void> verticleLoad = Future.future();
verticleLoad.setHandler(ar -> {
if (ar.succeeded()) {
this.startWebServer(startFuture);
} else {
startFuture.fail(ar.cause());
}
});
this.loadAppConfig(verticleLoad);
}
示例2: start
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
datasourceConfig = new DatasourceConfig(config().getJsonObject("datasource", new JsonObject()));
dbClient = JDBCClient.createShared(vertx, datasourceConfig.toJson(), "MusicStoreDS");
templateEngine = FreeMarkerTemplateEngine.create();
Completable couchbase = createCouchbaseClient().doOnSuccess(cluster -> couchbaseCluster = cluster)
.flatMap(v -> openBucket()).doOnSuccess(bucket -> albumCommentsBucket = bucket)
.flatMap(v -> loadProperties("couchbase/queries.xml")).doOnSuccess(props -> couchbaseQueries = props)
.toCompletable()
.andThen(Completable.defer(() -> setupBucket()));
Completable database = updateDB()
.andThen(loadProperties("db/queries.xml")).doOnSuccess(props -> dbQueries = props)
.toCompletable();
couchbase.mergeWith(database)
.andThen(Completable.fromAction(() -> setupAuthProvider()))
.andThen(Completable.defer(() -> setupWebServer()))
.subscribe(CompletableHelper.toObserver(startFuture));
}
示例3: start
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
Future<String> dbVerticleDeployment = Future.future(); // <1>
vertx.deployVerticle(new WikiDatabaseVerticle(), dbVerticleDeployment.completer()); // <2>
dbVerticleDeployment.compose(id -> { // <3>
Future<String> httpVerticleDeployment = Future.future();
vertx.deployVerticle(
"io.vertx.guides.wiki.HttpServerVerticle", // <4>
new DeploymentOptions().setInstances(2), // <5>
httpVerticleDeployment.completer());
return httpVerticleDeployment; // <6>
}).setHandler(ar -> { // <7>
if (ar.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(ar.cause());
}
});
}
示例4: WikiDatabaseServiceImpl
import io.vertx.core.Future; //導入依賴的package包/類
WikiDatabaseServiceImpl(JDBCClient dbClient, HashMap<SqlQuery, String> sqlQueries, Handler<AsyncResult<WikiDatabaseService>> readyHandler) {
this.dbClient = dbClient;
this.sqlQueries = sqlQueries;
dbClient.getConnection(ar -> {
if (ar.failed()) {
LOGGER.error("Could not open a database connection", ar.cause());
readyHandler.handle(Future.failedFuture(ar.cause()));
} else {
SQLConnection connection = ar.result();
connection.execute(sqlQueries.get(SqlQuery.CREATE_PAGES_TABLE), create -> {
connection.close();
if (create.failed()) {
LOGGER.error("Database preparation error", create.cause());
readyHandler.handle(Future.failedFuture(create.cause()));
} else {
readyHandler.handle(Future.succeededFuture(this));
}
});
}
});
}
示例5: getAuthInfo
import io.vertx.core.Future; //導入依賴的package包/類
/**
* Check for the Authentication info if required
*
* @return a future that resolves when successful got AuthInfo
*/
private Future<AuthInfo> getAuthInfo() {
Future<AuthInfo> result;
final String authName = this.getConsumerConfig().getAuthName();
if ((this.authInfo == null) && (authName != null)) {
result = Future.future();
final EventBus eb = this.getVertx().eventBus();
final String address = Constants.BUS_AUTHREQUEST + authName;
eb.send(address, null, replyHandler -> {
if (replyHandler.succeeded()) {
this.authInfo = (AuthInfo) replyHandler.result().body();
result.complete(this.authInfo);
} else {
result.fail(replyHandler.cause());
}
});
} else {
result = Future.succeededFuture(this.authInfo);
}
return result;
}
示例6: 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());
}
});
}
示例7: start
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public void start(Future<Void> startFuture) throws Exception {
HashMap<SqlQuery, String> sqlQueries = loadSqlQueries();
JDBCClient dbClient = JDBCClient.createShared(vertx, new JsonObject()
.put("url", config().getString(CONFIG_WIKIDB_JDBC_URL, "jdbc:hsqldb:file:db/wiki"))
.put("driver_class", config().getString(CONFIG_WIKIDB_JDBC_DRIVER_CLASS, "org.hsqldb.jdbcDriver"))
.put("max_pool_size", config().getInteger(CONFIG_WIKIDB_JDBC_MAX_POOL_SIZE, 30)));
WikiDatabaseService.create(dbClient, sqlQueries, ready -> {
if (ready.succeeded()) {
ProxyHelper.registerService(WikiDatabaseService.class, vertx, ready.result(), CONFIG_WIKIDB_QUEUE);
startFuture.complete();
} else {
startFuture.fail(ready.cause());
}
});
}
示例8: importTx
import io.vertx.core.Future; //導入依賴的package包/類
private Future<Void> importTx(StorableBlock block, JsonObject transactions) {
Future<Void> future = Future.future();
DeliveryOptions delivery = new DeliveryOptions().setSendTimeout(ONE_MINUTE);
if (config.isTxImport()) {
context.bus().send(TX_ADDR, transactions, delivery, done -> {
listener.onImported(block.getHash(), block.getNumber());
if (done.succeeded()) {
Throwable result = (Throwable) done.result().body();
if (result == null) {
future.complete();
} else {
future.fail(result);
}
} else {
future.fail(done.cause());
}
});
} else {
future.complete();
}
return future;
}
示例9: render
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public void render(
RoutingContext context, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
try {
Template template = cache.get(templateFileName);
if (template == null) {
synchronized (this) {
loader.setVertx(context.vertx());
template = handlebars.compile(templateFileName);
cache.put(templateFileName, template);
}
}
Context engineContext = Context.newBuilder(context.data()).resolver(getResolvers()).build();
handler.handle(Future.succeededFuture(Buffer.buffer(template.apply(engineContext))));
} catch (Exception ex) {
handler.handle(Future.failedFuture(ex));
}
}
示例10: fetchPage
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public WikiDatabaseService fetchPage(String name, Handler<AsyncResult<JsonObject>> resultHandler) {
dbClient.queryWithParams(sqlQueries.get(SqlQuery.GET_PAGE), new JsonArray().add(name), fetch -> {
if (fetch.succeeded()) {
JsonObject response = new JsonObject();
ResultSet resultSet = fetch.result();
if (resultSet.getNumRows() == 0) {
response.put("found", false);
} else {
response.put("found", true);
JsonArray row = resultSet.getResults().get(0);
response.put("id", row.getInteger(0));
response.put("rawContent", row.getString(1));
}
resultHandler.handle(Future.succeededFuture(response));
} else {
LOGGER.error("Database query error", fetch.cause());
resultHandler.handle(Future.failedFuture(fetch.cause()));
}
});
return this;
}
示例11: fetchWithRetry
import io.vertx.core.Future; //導入依賴的package包/類
<T> void fetchWithRetry(Logger logger, Callable<T> blockingHandler, Future<T> done) {
vertx.executeBlocking((Future<T> fut) -> {
try {
fut.complete(blockingHandler.call());
} catch (Exception e) {
fut.fail(e);
}
}, ar -> {
if (ar.failed() && !(ar.cause() instanceof AcmeRetryAfterException)) {
done.fail(ar.cause());
return;
}
if (ar.succeeded() && ar.result() != null) {
done.complete(ar.result());
return;
}
long nextSleep = ar.succeeded() ? 3000 : ((AcmeRetryAfterException) ar.cause()).getRetryAfter().getTime() - currentTimeMillis();
logger.info("Recheck in {}ms @ {}", nextSleep, new Date(System.currentTimeMillis() + nextSleep));
vertx.setTimer(nextSleep, timerId -> fetchWithRetry(logger, blockingHandler, done));
});
}
示例12: fetchAllPages
import io.vertx.core.Future; //導入依賴的package包/類
@Override
public WikiDatabaseService fetchAllPages(Handler<AsyncResult<JsonArray>> resultHandler) {
dbClient.query(sqlQueries.get(SqlQuery.ALL_PAGES), res -> {
if (res.succeeded()) {
JsonArray pages = new JsonArray(res.result()
.getResults()
.stream()
.map(json -> json.getString(0))
.sorted()
.collect(Collectors.toList()));
resultHandler.handle(Future.succeededFuture(pages));
} else {
LOGGER.error("Database query error", res.cause());
resultHandler.handle(Future.failedFuture(res.cause()));
}
});
return this;
}
示例13: deployOrderBookVerticle
import io.vertx.core.Future; //導入依賴的package包/類
private Future<String> deployOrderBookVerticle(DeploymentOptions options) {
Future<String> future = Future.future();
vertx.deployVerticle(new BittrexOrderBookVerticle(), options, res -> {
if (res.succeeded()) {
o_id = res.result();
System.out.println("OrderBookVerticle Deployment id is: " + res.result());
future.complete();
} else {
System.err.println("OrderBookVerticle failed: " + res.cause().getMessage());
future.fail(res.cause());
}
});
return future;
}
示例14: undeployWebSocketVerticle
import io.vertx.core.Future; //導入依賴的package包/類
private Future<String> undeployWebSocketVerticle() {
Future<String> future = Future.future();
if(ws_id == null){
future.complete();
} else {
vertx.undeploy(ws_id, res -> {
if (res.succeeded()) {
ws_id = null;
System.out.println("WebsocketVerticle undeployed");
future.complete();
} else {
System.err.println("WebsocketVerticle Undeployment failed: " + res.cause().getMessage());
future.fail(res.cause());
}
});
}
return future;
}
示例15: parseHeader
import io.vertx.core.Future; //導入依賴的package包/類
/**
* 解析報文頭。
*
* @param headerBuffer header Buffer
* @param expectedCommand expectedCommand
* @param expectedBodyLength expectedBodyLength
* @return async result of the length of the packet body
*/
public static Future<Long> parseHeader(Buffer headerBuffer, byte expectedCommand, long expectedBodyLength) {
if (headerBuffer.length() != HEADER_BYTE_LENGTH) {
return Future.failedFuture(new FdfsException("receive packet size" + headerBuffer.length()
+ " is not equal to the expected header size: " + HEADER_BYTE_LENGTH));
}
byte command = headerBuffer.getByte(PROTO_HEADER_CMD_INDEX);
if (command != expectedCommand) {
return Future.failedFuture(new FdfsException(
"receive command: " + command + " is not equal to the expected command: " + expectedCommand));
}
byte status = headerBuffer.getByte(PROTO_HEADER_STATUS_INDEX);
if (status != HEADER_STATUS_SUCCESS) {
return Future.failedFuture(new FdfsException("receive packet errno is: " + status));
}
long bodyLength = headerBuffer.getLong(0);
if (expectedBodyLength > 0 && bodyLength != expectedBodyLength) {
return Future.failedFuture(new FdfsException("receive packet body length: " + bodyLength
+ " is not equal to the expected: " + expectedBodyLength));
}
return Future.succeededFuture(bodyLength);
}