Example usage for io.vertx.core Future failedFuture

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

Introduction

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

Prototype

static <T> Future<T> failedFuture(String failureMessage) 

Source Link

Document

Create a failed future with the specified failure message.

Usage

From source file:io.reactiverse.pgclient.impl.SocketConnection.java

License:Apache License

void sendCancelRequestMessage(int processId, int secretKey, Handler<AsyncResult<Void>> handler) {
    Buffer buffer = Buffer.buffer(16);
    buffer.appendInt(16);//from ww w. j  ava 2s . co m
    // cancel request code
    buffer.appendInt(80877102);
    buffer.appendInt(processId);
    buffer.appendInt(secretKey);

    socket.write(buffer, ar -> {
        if (ar.succeeded()) {
            // directly close this connection
            if (status == Status.CONNECTED) {
                status = Status.CLOSING;
                socket.close();
            }
            handler.handle(Future.succeededFuture());
        } else {
            handler.handle(Future.failedFuture(ar.cause()));
        }
    });
}

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   ww  w  .ja  v a 2  s .  c om*/
            }
        }));
        break;
    case ST_COMPLETED:
        if (handler != null) {
            handler.handle(Future.failedFuture("Transaction already completed"));
        }
        break;
    }
}

From source file:io.reactiverse.pgclient.PgClient.java

License:Apache License

/**
 * Connects to the database and returns the connection if that succeeds.
 * <p/>/*from   w w  w.j a v  a 2  s  . c  om*/
 * The connection interracts directly with the database is not a proxy, so closing the
 * connection will close the underlying connection to the database.
 *
 * @param vertx the vertx instance
 * @param options the connect options
 * @param handler the handler called with the connection or the failure
 */
static void connect(Vertx vertx, PgConnectOptions options, Handler<AsyncResult<PgConnection>> handler) {
    Context ctx = Vertx.currentContext();
    if (ctx != null) {
        PgConnectionFactory client = new PgConnectionFactory(ctx, false, options);
        client.create(ar -> {
            if (ar.succeeded()) {
                Connection conn = ar.result();
                PgConnectionImpl p = new PgConnectionImpl(client, ctx, conn);
                conn.init(p);
                handler.handle(Future.succeededFuture(p));
            } else {
                handler.handle(Future.failedFuture(ar.cause()));
            }
        });
    } else {
        vertx.runOnContext(v -> {
            if (options.isUsingDomainSocket() && !vertx.isNativeTransportEnabled()) {
                handler.handle(Future.failedFuture("Native transport is not available"));
            } else {
                connect(vertx, options, handler);
            }
        });
    }
}

From source file:io.reactiverse.pgclient.pool.ConnectionQueue.java

License:Apache License

void fail(Throwable cause) {
    poll().handle(Future.failedFuture(cause));
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService addVertex(String iClassName, String iClusterName, JsonObject properties,
        Handler<AsyncResult<Record>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from   w  w  w. j a v  a  2  s  .c  om*/
    JsonObject _json = new JsonObject();
    _json.put("iClassName", iClassName);
    _json.put("iClusterName", iClusterName);
    _json.put("properties", properties);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "addVertex");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future
                    .succeededFuture(res.result().body() == null ? null : new Record(res.result().body())));
        }
    });
    return this;
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService updateVertex(String id, JsonObject properties, Handler<AsyncResult<Record>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from  ww w  . j  a  v a  2  s.  co m*/
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    _json.put("properties", properties);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "updateVertex");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future
                    .succeededFuture(res.result().body() == null ? null : new Record(res.result().body())));
        }
    });
    return this;
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService removeVertex(String id, Handler<AsyncResult<Record>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from  w w  w .j  a  va  2 s .c  o  m*/
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "removeVertex");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future
                    .succeededFuture(res.result().body() == null ? null : new Record(res.result().body())));
        }
    });
    return this;
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService getVertex(String id, Handler<AsyncResult<Record>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//  www .j  a  v a2 s .  c  o m
    JsonObject _json = new JsonObject();
    _json.put("id", id);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getVertex");
    _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future
                    .succeededFuture(res.result().body() == null ? null : new Record(res.result().body())));
        }
    });
    return this;
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService getVerticesOfClass(String iClassName, Handler<AsyncResult<List<Record>>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }//w  ww  .ja  v a  2 s  . c om
    JsonObject _json = new JsonObject();
    _json.put("iClassName", iClassName);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getVerticesOfClass");
    _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future.succeededFuture(res.result().body().stream().map(
                    o -> o instanceof Map ? new Record(new JsonObject((Map) o)) : new Record((JsonObject) o))
                    .collect(Collectors.toList())));
        }
    });
    return this;
}

From source file:io.rebind.vertx.orientdb.OrientDBServiceVertxEBProxy.java

License:Apache License

public OrientDBService getVertices(String iClassName, JsonObject vertexQuery,
        Handler<AsyncResult<List<Record>>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return this;
    }/*from ww w.j av  a 2s.  c  o  m*/
    JsonObject _json = new JsonObject();
    _json.put("iClassName", iClassName);
    _json.put("vertexQuery", vertexQuery);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "getVertices");
    _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future.succeededFuture(res.result().body().stream().map(
                    o -> o instanceof Map ? new Record(new JsonObject((Map) o)) : new Record((JsonObject) o))
                    .collect(Collectors.toList())));
        }
    });
    return this;
}