Search in sources :

Example 41 with Future

use of io.vertx.core.Future in project vertx-examples by vert-x3.

the class HttpVerticle method start.

@Override
public void start(Future<Void> startFuture) throws Exception {
    HttpServerOptions options = new HttpServerOptions().setPort(config().getInteger("port"));
    vertx.createHttpServer(options).requestHandler(request -> {
        String name = request.getParam("name");
        if (name == null) {
            request.response().setStatusCode(400).end("Missing name");
        } else {
            vertx.eventBus().<String>send("hello", name, ar -> {
                if (ar.succeeded()) {
                    request.response().end(ar.result().body());
                } else {
                    request.response().setStatusCode(500).end(ar.cause().getMessage());
                }
            });
        }
    }).listen(ar -> {
        if (ar.succeeded()) {
            startFuture.complete();
        } else {
            startFuture.fail(ar.cause());
        }
    });
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Future(io.vertx.core.Future) HttpServerOptions(io.vertx.core.http.HttpServerOptions)

Example 42 with Future

use of io.vertx.core.Future in project incubator-servicecomb-java-chassis by apache.

the class MockForRestServerVerticle method mockRestServerVerticle.

public void mockRestServerVerticle() {
    final HttpServer server = Mockito.mock(HttpServer.class);
    new MockUp<RestServerVerticle>() {

        @Mock
        private void startListen(HttpServer server, IpPort ipPort, Future<Void> startFuture) {
        }

        @Mock
        private HttpServer createHttpServer(boolean isHttp_2) {
            return server;
        }
    };
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Future(io.vertx.core.Future) MockUp(mockit.MockUp) IpPort(org.apache.servicecomb.foundation.common.net.IpPort)

Example 43 with Future

use of io.vertx.core.Future in project raml-module-builder by folio-org.

the class PostgresClient method get.

public void get(Object conn, String table, Class<?> clazz, Criterion filter, boolean returnCount, boolean setId, List<FacetField> facets, Handler<AsyncResult<Results>> replyHandler) {
    StringBuilder sb = new StringBuilder();
    StringBuilder fromClauseFromCriteria = new StringBuilder();
    if (filter != null) {
        sb.append(filter.toString());
        fromClauseFromCriteria.append(filter.from2String());
        if (fromClauseFromCriteria.length() > 0) {
            fromClauseFromCriteria.insert(0, ",");
        }
    }
    if (conn == null) {
        get(table, clazz, DEFAULT_JSONB_FIELD_NAME, fromClauseFromCriteria.toString() + sb.toString(), returnCount, true, setId, facets, replyHandler);
    } else {
        SQLConnection sqlConnection = ((Future<SQLConnection>) conn).result();
        doGet(sqlConnection, true, table, clazz, DEFAULT_JSONB_FIELD_NAME, fromClauseFromCriteria.toString() + sb.toString(), returnCount, true, setId, facets, replyHandler);
    }
}
Also used : SQLConnection(io.vertx.ext.sql.SQLConnection) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Example 44 with Future

use of io.vertx.core.Future in project raml-module-builder by folio-org.

the class PostgresClient method delete.

public void delete(Object conn, String table, Criterion filter, Handler<AsyncResult<UpdateResult>> replyHandler) {
    SQLConnection sqlConnection = ((Future<SQLConnection>) conn).result();
    StringBuilder sb = new StringBuilder();
    if (filter != null) {
        sb.append(filter.toString());
    }
    doDelete(sqlConnection, true, table, sb.toString(), replyHandler);
}
Also used : SQLConnection(io.vertx.ext.sql.SQLConnection) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Example 45 with Future

use of io.vertx.core.Future in project raml-module-builder by folio-org.

the class PostgresClient method rollbackTx.

// @Timer
@SuppressWarnings("unchecked")
public void rollbackTx(Object conn, Handler<AsyncResult<Object>> done) {
    SQLConnection sqlConnection = ((Future<SQLConnection>) conn).result();
    sqlConnection.rollback(res -> {
        sqlConnection.close();
        if (res.failed()) {
            log.error(res.cause().getMessage(), res.cause());
            done.handle(Future.failedFuture(res.cause()));
        } else {
            done.handle(Future.succeededFuture(res));
        }
    });
}
Also used : SQLConnection(io.vertx.ext.sql.SQLConnection) Future(io.vertx.core.Future) CompositeFuture(io.vertx.core.CompositeFuture)

Aggregations

Future (io.vertx.core.Future)375 HttpURLConnection (java.net.HttpURLConnection)195 Handler (io.vertx.core.Handler)174 List (java.util.List)166 Objects (java.util.Objects)164 JsonObject (io.vertx.core.json.JsonObject)163 Promise (io.vertx.core.Promise)159 Vertx (io.vertx.core.Vertx)157 Buffer (io.vertx.core.buffer.Buffer)149 Optional (java.util.Optional)147 Logger (org.slf4j.Logger)136 LoggerFactory (org.slf4j.LoggerFactory)136 CompositeFuture (io.vertx.core.CompositeFuture)127 ClientErrorException (org.eclipse.hono.client.ClientErrorException)127 Map (java.util.Map)122 Span (io.opentracing.Span)117 AsyncResult (io.vertx.core.AsyncResult)112 TracingHelper (org.eclipse.hono.tracing.TracingHelper)98 Constants (org.eclipse.hono.util.Constants)97 ArrayList (java.util.ArrayList)94