List of usage examples for io.vertx.core AsyncResult failed
boolean failed();
From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }//w w w. j a v a 2 s. c o m HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { handler.handle(ServiceException.fail(statusCode, httpResponse.statusMessage())); return null; } return httpResponse; }
From source file:com.github.ithildir.airbot.service.impl.MapQuestGeoServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }//from ww w .j a va2 s . c o m HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { handler.handle(ServiceException.fail(statusCode, httpResponse.bodyAsString())); return null; } return httpResponse; }
From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java
License:Open Source License
private <R, T> HttpResponse<T> _handleHttpResponse(AsyncResult<HttpResponse<T>> asyncResult, Handler<AsyncResult<R>> handler) { if (asyncResult.failed()) { handler.handle(Future.failedFuture(asyncResult.cause())); return null; }/* w ww.jav a2 s. c o m*/ HttpResponse<T> httpResponse = asyncResult.result(); int statusCode = httpResponse.statusCode(); if (statusCode != HttpResponseStatus.OK.code()) { JsonObject jsonObject = httpResponse.bodyAsJsonObject(); handler.handle(ServiceException.fail(statusCode, jsonObject.getString("message"), jsonObject)); return null; } return httpResponse; }
From source file:com.groupon.vertx.redis.RedisTransaction.java
License:Apache License
public Future<JsonObject> exec() { final Future<JsonObject> finalResult = Future.future(); if (!pendingCommands.isEmpty()) { JsonArray commands = new JsonArray(); final List<Future<JsonObject>> clientCommandResponses = new ArrayList<>(); clientCommandResponses.add(finalResult); RedisCommand command = pendingCommands.poll(); while (command != null) { clientCommandResponses.add(command.getClientCommandResponse()); commands.add(command.toJson()); command = pendingCommands.poll(); }//from w w w . ja v a2 s. co m JsonObject transactionCommands = new JsonObject(); transactionCommands.put("isTransaction", true); transactionCommands.put("commands", commands); final DeliveryOptions deliveryOptions = new DeliveryOptions().setSendTimeout(replyTimeout); eventBus.send(eventBusAddress, transactionCommands, deliveryOptions, new Handler<AsyncResult<Message<JsonObject>>>() { @Override public void handle(AsyncResult<Message<JsonObject>> messageAsyncResult) { JsonObject response; if (messageAsyncResult.failed()) { response = new JsonObject().put("status", "error").put("code", HttpURLConnection.HTTP_GATEWAY_TIMEOUT); } else { response = messageAsyncResult.result().body(); } int index = 0; executeResponse(clientCommandResponses.remove(0), response); // EXEC response for (Future<JsonObject> clientCommandResponse : clientCommandResponses) { if (clientCommandResponse != null) { JsonObject result = constructTransactionCommandResult(response, index); executeResponse(clientCommandResponse, result); } index++; } } }); } else { // Nothing to execute. finalResult.complete(null); } return finalResult; }
From source file:com.groupon.vertx.utils.deployment.DeploymentMonitorHandler.java
License:Apache License
private void checkForFailures(AsyncResult<String> result) { if (result.failed()) { failures.add(result.cause());//from w ww .j a v a2 s . c o m } else if (result.result().isEmpty()) { failures.add(new Exception("Empty deployment ID; failed to deploy verticle")); } }
From source file:com.thesoftwarefactory.vertx.web.mvc.impl.MvcServiceImpl.java
License:Apache License
protected void handleView(ViewResult viewResult, RoutingContext context) { context.put("model", viewResult.model()); templateEngine.render(context, viewResult.viewName(), new Handler<AsyncResult<Buffer>>() { @Override/*from w w w.jav a 2 s . c om*/ public void handle(AsyncResult<Buffer> event) { if (event.failed()) { context.fail(event.cause()); } else if (viewResult.isLayoutEnabled() && context.request().getParam(AJAX) == null) { handleLayoutAwareContent(event.result().toString(), viewResult.layoutPath(), context); } else { // convert ActionResult into Result.Content handleContent(ActionResult.content(event.result().toString()), context); } } }); }
From source file:com.thesoftwarefactory.vertx.web.mvc.impl.MvcServiceImpl.java
License:Apache License
@Override public void handle(AsyncResult<ActionResult> asyncResult, RoutingContext context) { Objects.requireNonNull(asyncResult); Objects.requireNonNull(context); if (asyncResult.failed()) { throw new RuntimeException(asyncResult.cause()); } else {// w w w . jav a 2 s . c o m context.vertx().runOnContext(ready -> { handle(asyncResult.result(), context); }); } }
From source file:de.braintags.netrelay.controller.persistence.AbstractAction.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void saveObjectInDatastore(Object ob, String entityName, RoutingContext context, IMapper mapper,
Handler<AsyncResult<Void>> handler) {
IWrite write = getPersistenceController().getNetRelay().getDatastore().createWrite(mapper.getMapperClass());
write.add(ob);/*from w w w . j av a2 s. c o m*/
write.save(res -> {
AsyncResult<IWriteResult> result = (AsyncResult<IWriteResult>) res;
if (result.failed()) {
handler.handle(Future.failedFuture(result.cause()));
} else {
LOGGER.info("adding new entity to context with key " + entityName);
addToContext(context, entityName, ob);
handler.handle(Future.succeededFuture());
}
});
}
From source file:de.elsibay.TicketEventbusBridge.java
License:Open Source License
private void checkToken(String authToken, BridgeEvent event, Handler<Session> successHandler) { if (authToken == null || "".equals(authToken)) { event.complete(false);/*from w ww . j ava 2s .co m*/ } // use the authToken as key to the user session this.sessionStore.get(authToken, (AsyncResult<Session> asyncSession) -> { if (asyncSession.failed()) { System.out.println("cannot get session with id " + authToken + " from sessionStore: " + asyncSession.cause().getMessage()); event.complete(false); } else { Session session = asyncSession.result(); if (session.isDestroyed()) { System.out.println("session with id " + authToken + " is destroyed"); event.complete(false); } else { JsonObject userData = session.get("user"); if (userData == null) { System.out.println("session with id " + authToken + " contains no user data "); event.complete(false); } else { successHandler.handle(session); } } } }); }
From source file:de.neofonie.deployer.StartVerticle.java
License:Open Source License
/** * Display the result of the deployment operation in a nice way. * /*from w w w.ja v a2 s . c o m*/ * @param reply The reply from the deployer. */ private void handleDeployResult(final AsyncResult<String> reply) { if (reply.failed()) { LOG.log(Level.SEVERE, "Loading modules failed! " + reply.cause().getMessage(), reply.cause()); vertx.close(); System.exit(1); } else { this.deployerId = reply.result(); LOG.info("Application ready."); } }