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:io.reactiverse.pgclient.impl.Transaction.java

License:Apache License

public void commit(Handler<AsyncResult<Void>> handler) {
    switch (status) {
    case ST_BEGIN:
    case ST_PENDING:
    case ST_PROCESSING:
        schedule(doQuery("COMMIT", ar -> {
            disposeHandler.handle(null);
            if (handler != null) {
                if (ar.succeeded()) {
                    handler.handle(Future.succeededFuture());
                } else {
                    handler.handle(Future.failedFuture(ar.cause()));
                }//from w  w  w  . j  a  v a  2 s  .  c  om
            }
        }));
        break;
    case ST_COMPLETED:
        if (handler != null) {
            handler.handle(Future.failedFuture("Transaction already completed"));
        }
        break;
    }
}

From source file:net.kuujo.vertigo.util.CountingCompletionHandler.java

License:Apache License

/**
 * Checks whether the handler should be called.
 *//*  w  w w .  j  av a 2  s .  c  o  m*/
private void checkDone() {
    if (doneHandler != null) {
        if (cause != null) {
            doneHandler.handle(Future.failedFuture(cause));
        } else {
            if (count == required) {
                doneHandler.handle(Future.succeededFuture());
            }
        }
    }
}

From source file:net.kuujo.vertigo.util.IncrementalCompletionHandler.java

License:Apache License

/**
 * Checks whether the handler should be called.
 *//*from  w w  w .  j a v  a  2 s. co m*/
protected void checkDone() {
    if (failed && doneHandler != null) {
        doneHandler.handle(Future.failedFuture(cause));
        doneHandler = null;
    } else if (complete && count == required) {
        doneHandler.handle(Future.succeededFuture());
        doneHandler = null;
    }
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

/**
 * Invoked before the http server is started.
 * <p>/*from   www . ja  v  a2 s.co m*/
 * May be overridden by sub-classes to provide additional startup handling.
 * 
 * @return A future indicating the outcome of the operation. The start up process fails if the returned future fails.
 */
protected Future<Void> preStartup() {

    return Future.succeededFuture();
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

private Future<HttpServer> bindSecureHttpServer(final Router router) {

    if (isSecurePortEnabled()) {
        Future<HttpServer> result = Future.future();
        final String bindAddress = server == null ? getConfig().getBindAddress() : "?";
        if (server == null) {
            server = vertx.createHttpServer(getHttpServerOptions());
        }/*from  w  ww.  j a va  2  s.  co  m*/
        server.requestHandler(router::accept).listen(done -> {
            if (done.succeeded()) {
                LOG.info("secure http server listening on {}:{}", bindAddress, server.actualPort());
                result.complete(done.result());
            } else {
                LOG.error("error while starting up secure http server", done.cause());
                result.fail(done.cause());
            }
        });
        return result;
    } else {
        return Future.succeededFuture();
    }
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

private Future<HttpServer> bindInsecureHttpServer(final Router router) {

    if (isInsecurePortEnabled()) {
        Future<HttpServer> result = Future.future();
        final String bindAddress = insecureServer == null ? getConfig().getInsecurePortBindAddress() : "?";
        if (insecureServer == null) {
            insecureServer = vertx.createHttpServer(getInsecureHttpServerOptions());
        }/*from  w  w  w  .  j a  va2s.c  o m*/
        insecureServer.requestHandler(router::accept).listen(done -> {
            if (done.succeeded()) {
                LOG.info("insecure http server listening on {}:{}", bindAddress, insecureServer.actualPort());
                result.complete(done.result());
            } else {
                LOG.error("error while starting up insecure http server", done.cause());
                result.fail(done.cause());
            }
        });
        return result;
    } else {
        return Future.succeededFuture();
    }
}

From source file:org.eclipse.hono.adapter.http.AbstractVertxBasedHttpProtocolAdapter.java

License:Open Source License

/**
 * Invoked after the Adapter has been shutdown successfully.
 * May be overridden by sub-classes to provide further shutdown handling.
 * //from www.j a v  a 2  s  .  c  om
 * @return A future that has to be completed when this operation is finished.
 */
protected Future<Void> postShutdown() {
    return Future.succeededFuture();
}

From source file:org.eclipse.hono.adapter.http.HonoAuthHandlerImpl.java

License:Open Source License

@Override
public void authorize(User user, Handler<AsyncResult<Void>> handler) {
    int requiredcount = authorities.size();
    if (requiredcount > 0) {
        if (user == null) {
            handler.handle(Future.failedFuture(FORBIDDEN));
            return;
        }/*from  ww w .  j  a  va 2  s .co  m*/

        AtomicInteger count = new AtomicInteger();
        AtomicBoolean sentFailure = new AtomicBoolean();

        Handler<AsyncResult<Boolean>> authHandler = res -> {
            if (res.succeeded()) {
                if (res.result()) {
                    if (count.incrementAndGet() == requiredcount) {
                        // Has all required authorities
                        handler.handle(Future.succeededFuture());
                    }
                } else {
                    if (sentFailure.compareAndSet(false, true)) {
                        handler.handle(Future.failedFuture(FORBIDDEN));
                    }
                }
            } else {
                handler.handle(Future.failedFuture(res.cause()));
            }
        };
        for (String authority : authorities) {
            if (!sentFailure.get()) {
                user.isAuthorized(authority, authHandler);
            }
        }
    } else {
        // No auth required
        handler.handle(Future.succeededFuture());
    }
}

From source file:org.eclipse.hono.adapter.http.HonoAuthHandlerImpl.java

License:Open Source License

protected final void parseAuthorization(RoutingContext ctx, boolean optional,
        Handler<AsyncResult<String>> handler) {

    final HttpServerRequest request = ctx.request();
    final String authorization = request.headers().get(HttpHeaders.AUTHORIZATION);

    if (authorization == null) {
        if (optional) {
            // this is allowed
            handler.handle(Future.succeededFuture());
        } else {//from  w  w w  .  j  a  va  2s .  c o  m
            handler.handle(Future.failedFuture(UNAUTHORIZED));
        }
        return;
    }

    try {
        int idx = authorization.indexOf(' ');

        if (idx <= 0) {
            handler.handle(Future.failedFuture(BAD_REQUEST));
            return;
        }

        if (!type.is(authorization.substring(0, idx))) {
            handler.handle(Future.failedFuture(UNAUTHORIZED));
            return;
        }

        handler.handle(Future.succeededFuture(authorization.substring(idx + 1)));
    } catch (RuntimeException e) {
        handler.handle(Future.failedFuture(e));
    }
}

From source file:org.eclipse.hono.adapter.http.HonoBasicAuthHandler.java

License:Open Source License

/**
 * Extracts authentication information from the <em>Authorization</em>
 * header of an HTTP request.// w  ww  .  j a va  2  s . c  o m
 * 
 * @param ctx The routing context that contains the HTTP request.
 * @param optional Indicates whether the authorization header is mandatory.
 * @param handler The handler to invoke with the authentication info.
 */
protected final void parseAuthorization(final RoutingContext ctx, final boolean optional,
        final Handler<AsyncResult<String>> handler) {

    final HttpServerRequest request = ctx.request();
    final String authorization = request.headers().get(HttpHeaders.AUTHORIZATION);

    if (authorization == null) {
        if (optional) {
            // this is allowed
            handler.handle(Future.succeededFuture());
        } else {
            handler.handle(Future.failedFuture(UNAUTHORIZED));
        }
        return;
    }

    try {
        final int idx = authorization.indexOf(' ');

        if (idx <= 0) {
            handler.handle(Future.failedFuture(BAD_REQUEST));
            return;
        }

        if (!"Basic".equalsIgnoreCase(authorization.substring(0, idx))) {
            handler.handle(Future.failedFuture(UNAUTHORIZED));
            return;
        }

        handler.handle(Future.succeededFuture(authorization.substring(idx + 1)));
    } catch (RuntimeException e) {
        handler.handle(Future.failedFuture(e));
    }
}