List of usage examples for io.vertx.core Future future
future
From source file:org.eclipse.hono.tests.mqtt.TelemetryMqttQoS1IT.java
License:Open Source License
@Override protected Future<Void> send(final String tenantId, final String deviceId, final Buffer payload, final boolean useShortTopicName) { final String topic = String.format(TOPIC_TEMPLATE, useShortTopicName ? TelemetryConstants.TELEMETRY_ENDPOINT_SHORT : TelemetryConstants.TELEMETRY_ENDPOINT, tenantId, deviceId);//from w w w. j av a 2s . c o m final Future<Void> result = Future.future(); mqttClient.publishCompletionHandler(id -> result.complete()); mqttClient.publish(topic, payload, MqttQoS.AT_LEAST_ONCE, false, false); return result; }
From source file:org.eclipse.hono.tests.registry.DeviceRegistryAmqpTestSupport.java
License:Open Source License
/** * Closes the connection of the provided client to the device registry service. * <p>//from www. j a va 2 s .c om * Any senders or consumers opened by this client will be implicitly closed as well. Any subsequent attempts to * connect this client again will fail. * * @param vertx The Vert.x instance on which the client is executed on. * @param ctx The test context that the tests are executed on. * @param client The client to shutdown. * @throws NullPointerException if any of the parameters is {@code null}. */ protected static void shutdownDeviceRegistryClient(final TestContext ctx, final Vertx vertx, final HonoClient client) { final Future<Void> clientTracker = Future.future(); if (client != null) { client.shutdown(clientTracker.completer()); } else { clientTracker.complete(); } clientTracker.otherwiseEmpty().compose(s -> { final Future<Void> vertxTracker = Future.future(); vertx.close(vertxTracker.completer()); return vertxTracker; }).setHandler(ctx.asyncAssertSuccess()); }
From source file:org.eclipse.hono.vertx.example.base.HonoConsumerBase.java
License:Open Source License
/** * Initiate the connection and set the message handling method to treat data that is received. * * @throws Exception Thrown if the latch is interrupted during waiting or if the read from System.in throws an IOException. *//*from ww w . ja v a 2 s. co m*/ protected void consumeData() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final Future<MessageConsumer> consumerFuture = Future.future(); consumerFuture.setHandler(result -> { if (!result.succeeded()) { System.err.println("honoClient could not create telemetry consumer for " + HonoExampleConstants.HONO_AMQP_CONSUMER_HOST + ":" + HonoExampleConstants.HONO_AMQP_CONSUMER_PORT + " : " + result.cause()); } latch.countDown(); }); honoClient.connect(this::onDisconnect).compose(connectedClient -> createConsumer()) .setHandler(consumerFuture.completer()); latch.await(); if (consumerFuture.succeeded()) { System.in.read(); } vertx.close(); }
From source file:org.eclipse.hono.vertx.example.base.HonoSenderBase.java
License:Open Source License
/** * Get both Hono clients and connect them to Hono's microservices. * * @return The result of the creation and connection of the Hono clients. *//*from ww w. ja va 2 s .c o m*/ private Future<Void> getHonoClients() { // we need two clients to get it working, define futures for them final Future<RegistrationClient> registrationClientTracker = getRegistrationClient(); final Future<MessageSender> messageSenderTracker = getMessageSender(); final Future<Void> result = Future.future(); CompositeFuture.all(registrationClientTracker, messageSenderTracker).setHandler(compositeResult -> { if (compositeResult.failed()) { System.err.println("hono clients could not be created : " + compositeResult.cause().getMessage()); result.fail(compositeResult.cause()); } else { registrationClient = registrationClientTracker.result(); messageSender = messageSenderTracker.result(); result.complete(); } }); return result; }
From source file:org.eclipse.hono.vertx.example.base.HonoSenderBase.java
License:Open Source License
private Future<Void> closeClients() { final Future<Void> messagingClient = Future.future(); final Future<Void> regClient = Future.future(); honoMessagingClient.shutdown(messagingClient.completer()); honoRegistryClient.shutdown(regClient.completer()); return CompositeFuture.all(messagingClient, regClient).compose(ok -> Future.succeededFuture()); }
From source file:org.entcore.directory.services.impl.DefaultUserBookService.java
License:Open Source License
public void cleanAvatarCache(List<String> usersId, final Handler<Boolean> handler) { @SuppressWarnings("rawtypes") List<Future> futures = new ArrayList<>(); for (String u : usersId) { Future<Boolean> future = Future.future(); futures.add(future);// w w w . j a v a2 s . c om futures.add(cleanAvatarCache(u)); } CompositeFuture.all(futures).setHandler(finishRes -> handler.handle(finishRes.succeeded())); }
From source file:org.entcore.directory.services.impl.DefaultUserBookService.java
License:Open Source License
private Future<Boolean> cleanAvatarCache(String userId) { Future<Boolean> future = Future.future(); this.avatarStorage.findByFilenameEndingWith(userId, res -> { if (res.succeeded() && res.result().size() > 0) { this.avatarStorage.removeFiles(res.result(), removeRes -> { future.complete(true);/*w w w. j a v a 2s. c om*/ }); } else { future.complete(false); } }); return future; }
From source file:org.entcore.directory.services.impl.DefaultUserBookService.java
License:Open Source License
private Future<Boolean> cacheAvatarFromUserBook(String userId, Optional<String> pictureId, Boolean remove) { // clean avatar when changing or when removing Future<Boolean> futureClean = (pictureId.isPresent() || remove) ? cleanAvatarCache(userId) : Future.succeededFuture(); return futureClean.compose(res -> { if (!pictureId.isPresent()) { return Future.succeededFuture(); }/* w ww . j a v a 2 s . com*/ Future<Boolean> futureCopy = Future.future(); this.wsHelper.getDocument(pictureId.get(), resDoc -> { if (resDoc.succeeded() && "ok".equals(resDoc.result().body().getString("status"))) { JsonObject document = resDoc.result().body().getJsonObject("result"); String fileId = document.getString("file"); // Extensions are not used by storage String defaultFilename = avatarFileNameFromUserId(userId, Optional.empty()); // JsonObject thumbnails = document.getJsonObject("thumbnails", new JsonObject()); Map<String, String> filenamesByIds = new HashMap<>(); filenamesByIds.put(fileId, defaultFilename); for (String size : thumbnails.fieldNames()) { filenamesByIds.put(thumbnails.getString(size), avatarFileNameFromUserId(userId, Optional.of(size))); } // TODO avoid buffer to improve performances and avoid cache every time List<Future> futures = new ArrayList<>(); for (Entry<String, String> entry : filenamesByIds.entrySet()) { String cFileId = entry.getKey(); String cFilename = entry.getValue(); Future<JsonObject> future = Future.future(); futures.add(future); this.wsHelper.readFile(cFileId, buffer -> { if (buffer != null) { this.avatarStorage.writeBuffer(FileUtils.stripExtension(cFilename), buffer, "", cFilename, wRes -> { future.complete(wRes); }); } else { future.fail("Cannot read file from workspace storage. ID =: " + cFileId); } }); } // CompositeFuture.all(futures) .setHandler(finishRes -> futureCopy.complete(finishRes.succeeded())); } }); return futureCopy; }); }
From source file:org.entcore.directory.services.impl.DefaultUserBookService.java
License:Open Source License
private Future<Boolean> sendAvatar(HttpServerRequest request, String fileId) { Future<Boolean> future = Future.future(); // file storage doesnt keep extension JsonObject meta = new JsonObject().put("content-type", "image/*"); this.avatarStorage.fileStats(fileId, stats -> { if (stats.succeeded()) { Date modified = stats.result().getLastModified(); boolean hasBeenModified = HttpHeaderUtils.checkIfModifiedSince(request.headers(), modified); boolean hasChangedEtag = !ETag.check(request, fileId); HttpHeaderUtils.addHeaderLastModified(request.response().headers(), modified); // check if file is modified or fileid has changed if (hasBeenModified || hasChangedEtag) { // TODO send file renvoie tout le chemin de fichier dans l ETAG? this.avatarStorage.sendFile(fileId, fileId, request, true, meta); future.complete(true);/*from w w w .j a v a 2 s . c o m*/ } else { Renders.notModified(request); future.complete(true); } } else { future.complete(false); } }); return future; }
From source file:org.folio.auth.login_module.impl.DummyUserSource.java
@Override public Future<UserResult> getUser(String username) { Future<UserResult> future = Future.future(); future.complete(new UserResult(username)); return future; }