Example usage for io.vertx.core Future succeededFuture

List of usage examples for io.vertx.core Future succeededFuture

Introduction

In this page you can find the example usage for io.vertx.core Future succeededFuture.

Prototype

static <T> Future<T> succeededFuture() 

Source Link

Document

Create a succeeded future with a null result

Usage

From source file:org.eclipse.hono.tests.CrudHttpClient.java

License:Open Source License

/**
 * Updates a resource using an HTTP PUT request.
 * //from w w w  .j  a va  2 s. c o  m
 * @param uri The resource to update.
 * @param body The content to update the resource with.
 * @param contentType The content type to set in the request.
 * @param successPredicate A predicate on the returned HTTP status code for determining success.
 * @return A future that will succeed if the predicate evaluates to {@code true}.
 * @throws NullPointerException if URI or predicate are {@code null}.
 */
public Future<Void> update(final String uri, final Buffer body, final String contentType,
        final Predicate<Integer> successPredicate) {

    final MultiMap headers = Optional.ofNullable(contentType)
            .map(ct -> MultiMap.caseInsensitiveMultiMap().add(HttpHeaders.CONTENT_TYPE, ct)).orElse(null);

    return update(uri, body, headers, successPredicate).compose(ok -> Future.succeededFuture());
}

From source file:org.eclipse.hono.util.AggregatingInvocationResultHandler.java

License:Open Source License

@Override
public void handle(final Boolean succeeded) {
    if (succeeded) {
        successfulResponses.incrementAndGet();
    } else {/*from w  w  w.ja  va  2  s. co m*/
        unsuccessfulResponses.incrementAndGet();
    }
    if (successfulResponses.get() + unsuccessfulResponses.get() == expectedNoOfResults) {
        if (unsuccessfulResponses.get() > 0) {
            overallResultHandler.handle(Future.failedFuture(
                    String.format("%d invocations have been unsuccessful", unsuccessfulResponses.get())));
        } else {
            LOG.debug("all invocations have succeeded");
            overallResultHandler.handle(Future.succeededFuture());
        }
    }
}

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

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();
        }//from www .  j  a  va2 s.c o m
        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.etourdot.vertx.marklogic.http.impl.DefaultRestService.java

License:Open Source License

@Override
public void isAvalaible(Handler<AsyncResult<Void>> resultHandler) {
    newMarklogicRequest().head(PING_URL).execute(response -> {
        if (response instanceof ErrorResponse
                || HttpResponseStatus.UNAUTHORIZED.code() == response.statusCode()) {
            logger.debug("RestService unavailable !!!");
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        } else {/*w w w.j  a  v  a 2  s.  co  m*/
            logger.debug("RestService available");
            resultHandler.handle(Future.succeededFuture());
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicAdminImpl.java

License:Open Source License

void createRESTAppServer(RestApiOptions restApiOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(restApiOption, "restApiOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    marklogicRequest.post(REST_APIS).withBody(restApiOption.toJson()).execute(response -> {
        if (HttpResponseStatus.CREATED.code() == response.statusCode()) {
            resultHandler.handle(Future.succeededFuture());
        } else {//from   w w w  .  j  a v  a2  s.c o  m
            response.contentHandler(
                    buffer -> resultHandler.handle(Future.failedFuture(buffer.toJsonObject().encode())));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void createForest(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "forestsOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    marklogicRequest.post(MANAGE_FORESTS).withBody(forestsOption.toJson()).execute(response -> {
        if (HttpResponseStatus.CREATED.code() == response.statusCode()) {
            resultHandler.handle(Future.succeededFuture());
        } else {//from   ww  w. j a  v a  2  s. c  o  m
            response.contentHandler(
                    buffer -> resultHandler.handle(Future.failedFuture(buffer.toJsonObject().encode())));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void deleteForest(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "config cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");
    requireNonNull(forestsOption.getName(), "name cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_FORESTS, forestsOption);
    marklogicRequest.delete(serverHttpString);
    if (forestsOption.hasLevel()) {
        marklogicRequest.addParam(LEVEL, forestsOption.getLevel());
    }/*  w ww  .  j  ava 2 s  . com*/
    if (forestsOption.hasReplicas()) {
        marklogicRequest.addParam(REPLICAS, forestsOption.getReplicas());
    }

    marklogicRequest.execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void setForestProps(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "forestsOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");
    requireNonNull(forestsOption.getName(), "forest-name cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_FORESTS, forestsOption) + "/properties";
    marklogicRequest.put(serverHttpString).execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {//from   w w w.  j  a  v a  2  s . c om
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void setDatabaseProps(DatabasesOptions databasesOptions, Handler<AsyncResult<String>> resultHandler) {
    requireNonNull(databasesOptions, "databaseOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_DATABASES, databasesOptions) + "/properties";
    marklogicRequest.put(serverHttpString).withBody(databasesOptions.getOperation()).execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {/*from   ww w .j a v a 2  s  .co m*/
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}