List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:com.themonkee.vertx.web.impl.MongoSessionStoreImpl.java
License:Open Source License
@Override public void delete(String id, Handler<AsyncResult<Boolean>> handler) { this.mongoClient.removeDocument(this.sessionCollection, new JsonObject().put("_id", id), r -> handler.handle(Future.succeededFuture(r.succeeded()))); }
From source file:com.themonkee.vertx.web.impl.MongoSessionStoreImpl.java
License:Open Source License
@Override public void put(Session session, Handler<AsyncResult<Boolean>> handler) { SessionImpl s = (SessionImpl) session; this.mongoClient.replaceDocumentsWithOptions(this.sessionCollection, new JsonObject().put("_id", s.id()), s.toJsonObject(), new UpdateOptions().setUpsert(true).setMulti(false), r -> handler.handle(Future.succeededFuture(r.succeeded()))); }
From source file:com.themonkee.vertx.web.impl.MongoSessionStoreImpl.java
License:Open Source License
@Override public void clear(Handler<AsyncResult<Boolean>> handler) { this.mongoClient.removeDocuments(this.sessionCollection, new JsonObject(), c -> handler.handle(Future.succeededFuture(c.succeeded()))); }
From source file:com.themonkee.vertx.web.impl.MongoSessionStoreImpl.java
License:Open Source License
@Override public void size(Handler<AsyncResult<Integer>> handler) { this.mongoClient.count(this.sessionCollection, null, c -> { Long result = c.result(); Integer x = result.intValue(); handler.handle(Future.succeededFuture(x)); });/*from www . j ava 2s. c o m*/ }
From source file:de.braintags.netrelay.controller.api.DataTableLinkDescriptor.java
License:Open Source License
private void querySuccess(IQuery<?> q, Handler<AsyncResult<IQuery<?>>> handler) { handler.handle(Future.succeededFuture(q)); }
From source file:de.braintags.netrelay.controller.api.DataTablesController.java
License:Open Source License
private void execute(IQuery<?> query, DataTableLinkDescriptor descr, long tableCount, Handler<AsyncResult<JsonObject>> handler) { query.execute(qr -> {/*from w ww. j ava 2 s. co m*/ if (qr.failed()) { handler.handle(Future.failedFuture(qr.cause())); } else { LOGGER.info(qr.result().getOriginalQuery()); long totalResult = qr.result().getCompleteResult(); qr.result().toArray(result -> { if (result.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { Object[] selection = result.result(); LOGGER.info("SELECTION SIZE: " + selection.length); if (selection.length == 0) { handler.handle(Future.succeededFuture(createJsonObject(query.getMapper(), new ArrayList<IStoreObject<?, ?>>(), descr, totalResult, tableCount))); } else { IStoreObjectFactory<?> sf = mapperFactory.getStoreObjectFactory(); sf.createStoreObjects(query.getMapper(), Arrays.asList(selection), str -> { if (str.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { List tmpSel = str.result(); JsonObject jo = createJsonObject(query.getMapper(), tmpSel, descr, totalResult, tableCount); handler.handle(Future.succeededFuture(jo)); } }); } } }); } }); }
From source file:de.braintags.netrelay.controller.api.MailController.java
License:Open Source License
/** * The method composes and sends a mail message. Note: this method won't cause a fail on the given handler, it calls * always the success method of the handler. If errors occured, they will be set inside the returned * {@link MailSendResult},/*from ww w .ja v a 2s . c om*/ * where then the property {@link MailSendResult#success} is set to false * * @param context * the current context * @param mailClient * the {@link MailClient} to be used * @param prefs * the {@link MailPreferences} created from the controller properties * @param handler * the handler to be informed. The handler receives an instance of {@link MailSendResult} */ public static void sendMail(RoutingContext context, MailClient mailClient, MailPreferences prefs, Handler<AsyncResult<MailSendResult>> handler) { try { if (mailClient == null) { throw new InitException(UNCONFIGURED_ERROR); } URI uri = URI.create(context.request().absoluteURI()); context.put("REQUEST_HOST", prefs.hostName == null ? uri.getHost() : prefs.hostName); context.put("REQUEST_PORT", prefs.port <= 0 ? uri.getPort() : prefs.port); context.put("REQUEST_SCHEME", prefs.scheme == null ? uri.getScheme() : prefs.scheme); createMailMessage(context, prefs, result -> { if (result.failed()) { LOGGER.error("", result.cause()); MailSendResult msResult = new MailSendResult(result.cause()); handler.handle(Future.succeededFuture(msResult)); } else { MailMessage email = result.result(); sendMessage(mailClient, email, handler); } }); } catch (Exception e) { LOGGER.error("", e); MailSendResult msResult = new MailSendResult(e); handler.handle(Future.succeededFuture(msResult)); } }
From source file:de.braintags.netrelay.controller.api.MailController.java
License:Open Source License
/** * @param email// ww w .j a v a 2 s .co m * @param sendResult */ private static void sendMessage(MailClient mailClient, MailMessage email, Handler<AsyncResult<MailSendResult>> handler) { LOGGER.info("Going to send message"); mailClient.sendMail(email, result -> { if (result.failed()) { LOGGER.error("Error in sending Mail occured", new RuntimeException(result.cause())); MailSendResult msResult = new MailSendResult(result); handler.handle(Future.succeededFuture(msResult)); } else { MailSendResult msResult = new MailSendResult(result); LOGGER.info(msResult.toString()); handler.handle(Future.succeededFuture(msResult)); } }); }
From source file:de.braintags.netrelay.controller.api.MailController.java
License:Open Source License
private static void checkInlineMessage(RoutingContext context, MailPreferences prefs, MailMessage msg, Handler<AsyncResult<MailMessage>> handler) { if (prefs.inline) { parseInlineMessage(context, prefs, msg, handler); } else {//from ww w. j av a 2 s. co m handler.handle(Future.succeededFuture(msg)); } }
From source file:de.braintags.netrelay.controller.api.MailController.java
License:Open Source License
/** * Replaces src-attributes of img-tags with cid to represent the correct inline-attachment * /*from ww w .j a v a 2s .com*/ * @param msg * @param textValue * @param helper */ private static void parseInlineMessage(RoutingContext context, MailPreferences prefs, MailMessage msg, Handler<AsyncResult<MailMessage>> handler) { List<MailAttachment> attachments = new ArrayList<>(); StringBuffer result = new StringBuffer(); // group1: everything before the image src, group2:filename inside the "" of the src element, group4: everything // after the image src String htmlMessage = msg.getHtml(); if (htmlMessage != null) { Matcher matcher = IMG_PATTERN.matcher(htmlMessage); while (matcher.find()) { String imageSource = matcher.group(2); String cid = getContentId(); URI imgUrl = makeAbsoluteURI(imageSource); if (imgUrl != null) { MailAttachment attachment = createAttachment(context, imgUrl, cid); matcher.appendReplacement(result, "$1cid:" + cid + "$3"); attachments.add(attachment); } else { matcher.appendReplacement(result, "$0"); } } matcher.appendTail(result); } msg.setHtml(result.toString()); if (attachments.isEmpty()) { handler.handle(Future.succeededFuture(msg)); } else { CounterObject co = new CounterObject<>(attachments.size(), handler); for (MailAttachment attachment : attachments) { readData(prefs, (UriMailAttachment) attachment, rr -> { if (rr.failed()) { co.setThrowable(rr.cause()); } else if (co.reduce()) { msg.setInlineAttachment(attachments); handler.handle(Future.succeededFuture(msg)); } }); if (co.isError()) { break; } } } }