本文整理匯總了Java中io.vertx.core.AsyncResult類的典型用法代碼示例。如果您正苦於以下問題:Java AsyncResult類的具體用法?Java AsyncResult怎麽用?Java AsyncResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AsyncResult類屬於io.vertx.core包,在下文中一共展示了AsyncResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: WikiDatabaseServiceImpl
import io.vertx.core.AsyncResult; //導入依賴的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));
}
});
}
});
}
示例2: send
import io.vertx.core.AsyncResult; //導入依賴的package包/類
public MailService send(MailMessage message, Handler<AsyncResult<MailResult>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return this;
}
JsonObject _json = new JsonObject();
_json.put("message", message == null ? null : message.toJson());
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "send");
_vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new MailResult(res.result().body())));
}
});
return this;
}
示例3: computeEvaluation
import io.vertx.core.AsyncResult; //導入依賴的package包/類
private void computeEvaluation(WebClient webClient, Handler<AsyncResult<Double>> resultHandler) {
// We need to call the service for each company in which we own shares
Flowable.fromIterable(portfolio.getShares().entrySet())
// For each, we retrieve the value
.flatMapSingle(entry -> getValueForCompany(webClient, entry.getKey(), entry.getValue()))
// We accumulate the results
.toList()
// And compute the sum
.map(list -> list.stream().mapToDouble(x -> x).sum())
// We report the result or failure
.subscribe((sum, err) -> {
if (err != null) {
System.out.println("Evaluation of the portfolio failed " + err.getMessage());
resultHandler.handle(Future.failedFuture(err));
} else {
System.out.println("Evaluation of the portfolio succeeeded");
resultHandler.handle(Future.succeededFuture(sum));
}
});
}
示例4: pageUpdateHandler
import io.vertx.core.AsyncResult; //導入依賴的package包/類
private void pageUpdateHandler(RoutingContext context) {
String title = context.request().getParam("title");
Handler<AsyncResult<Void>> handler = reply -> {
if (reply.succeeded()) {
context.response().setStatusCode(303);
context.response().putHeader("Location", "/wiki/" + title);
context.response().end();
} else {
context.fail(reply.cause());
}
};
String markdown = context.request().getParam("markdown");
if ("yes".equals(context.request().getParam("newPage"))) {
dbService.createPage(title, markdown, handler);
} else {
dbService.savePage(Integer.valueOf(context.request().getParam("id")), markdown, handler);
}
}
示例5: fileInfo
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public FdfsClient fileInfo(FdfsFileId fileId, Handler<AsyncResult<FdfsFileInfo>> handler) {
getTracker().setHandler(tracker -> {
if (tracker.succeeded()) {
tracker.result().getUpdateStorage(fileId, storage -> {
if (storage.succeeded()) {
storage.result().fileInfo(fileId, fileInfo -> {
handler.handle(fileInfo);
});
} else {
handler.handle(Future.failedFuture(storage.cause()));
}
});
} else {
handler.handle(Future.failedFuture(tracker.cause()));
}
});
return this;
}
示例6: sell
import io.vertx.core.AsyncResult; //導入依賴的package包/類
public void sell(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
if (closed) {
resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return;
}
JsonObject _json = new JsonObject();
_json.put("amount", amount);
_json.put("quote", quote);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "sell");
_vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(res.result().body() == null ? null : new Portfolio(res.result().body())));
}
});
}
示例7: connect
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public RpcClient connect(final String name,
final String address,
final JsonObject data,
final Handler<AsyncResult<JsonObject>> handler) {
return this.connect(RpcHelper.on(name, address), data, handler);
}
示例8: fetchAllPagesData
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler) {
dbClient.query(sqlQueries.get(SqlQuery.ALL_PAGES_DATA), queryResult -> {
if (queryResult.succeeded()) {
resultHandler.handle(Future.succeededFuture(queryResult.result().getRows()));
} else {
LOGGER.error("Database query error", queryResult.cause());
resultHandler.handle(Future.failedFuture(queryResult.cause()));
}
});
return this;
}
示例9: buy
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public void buy(int amount, JsonObject quote, Handler<AsyncResult<Portfolio>> resultHandler) {
if (amount <= 0) {
resultHandler.handle(Future.failedFuture("Cannot buy " + quote.getString("name") + " - the amount must be " +
"greater than 0"));
return;
}
if (quote.getInteger("shares") < amount) {
resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " - not enough " +
"stocks on the market (" + quote.getInteger("shares") + ")"));
return;
}
double price = amount * quote.getDouble("ask");
String name = quote.getString("name");
// 1) do we have enough money
if (portfolio.getCash() >= price) {
// Yes, buy it
portfolio.setCash(portfolio.getCash() - price);
int current = portfolio.getAmount(name);
int newAmount = current + amount;
portfolio.getShares().put(name, newAmount);
sendActionOnTheEventBus("BUY", amount, quote, newAmount);
resultHandler.handle(Future.succeededFuture(portfolio));
} else {
resultHandler.handle(Future.failedFuture("Cannot buy " + amount + " of " + name + " - " + "not enough money, " +
"need " + price + ", has " + portfolio.getCash()));
}
}
示例10: handle
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public void handle(AsyncResult<T> ar) {
if (ar.succeeded()) {
complete(ar.result());
} else {
completeExceptionally(ar.cause());
}
}
示例11: listen
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public HttpServer listen(int port, Handler<AsyncResult<HttpServer>> listenHandler) {
localPort = port;
listenHandler.handle(Future.succeededFuture(this));
processRequest();
return this;
}
示例12: savePage
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public WikiDatabaseService savePage(int id, String markdown, Handler<AsyncResult<Void>> resultHandler) {
JsonArray data = new JsonArray().add(markdown).add(id);
dbClient.updateWithParams(sqlQueries.get(SqlQuery.SAVE_PAGE), data, res -> {
if (res.succeeded()) {
resultHandler.handle(Future.succeededFuture());
} else {
LOGGER.error("Database query error", res.cause());
resultHandler.handle(Future.failedFuture(res.cause()));
}
});
return this;
}
示例13: handleSimpleDbReply
import io.vertx.core.AsyncResult; //導入依賴的package包/類
private void handleSimpleDbReply(RoutingContext context, AsyncResult<Void> reply) {
if (reply.succeeded()) {
context.response().setStatusCode(200);
context.response().putHeader("Content-Type", "application/json");
context.response().end(new JsonObject().put("success", true).encode());
} else {
context.response().setStatusCode(500);
context.response().putHeader("Content-Type", "application/json");
context.response().end(new JsonObject()
.put("success", false)
.put("error", reply.cause().getMessage()).encode());
}
}
示例14: insertReturningPrimaryAsync
import io.vertx.core.AsyncResult; //導入依賴的package包/類
/**
* Performs an async <code>INSERT</code> statement for a given POJO and passes the primary key
* to the <code>resultHandler</code>. When the value could not be inserted, the <code>resultHandler</code>
* will fail.
* @param object The POJO to be inserted
* @param resultHandler the resultHandler. In case of Postgres or when PK length is greater 1 or PK is not of
* type int or long, the resultHandler will be in error state.
*/
default void insertReturningPrimaryAsync(P object, Handler<AsyncResult<T>> resultHandler){
VertxDAOHelper.insertReturningPrimaryAsync(object,this, (query,fun)->{
client().insertReturning(query,res -> {
if (res.failed()) {
resultHandler.handle(Future.failedFuture(res.cause()));
} else {
resultHandler.handle(Future.succeededFuture(fun.apply(res.result())));
}
});
return null;
});
}
示例15: fetchAllPagesData
import io.vertx.core.AsyncResult; //導入依賴的package包/類
@Override
public WikiDatabaseService fetchAllPagesData(Handler<AsyncResult<List<JsonObject>>> resultHandler) {
dbClient.rxQuery(sqlQueries.get(SqlQuery.ALL_PAGES_DATA))
.map(ResultSet::getRows)
.subscribe(RxHelper.toSubscriber(resultHandler));
return this;
}