Example usage for io.vertx.core Vertx isNativeTransportEnabled

List of usage examples for io.vertx.core Vertx isNativeTransportEnabled

Introduction

In this page you can find the example usage for io.vertx.core Vertx isNativeTransportEnabled.

Prototype

@CacheReturn
boolean isNativeTransportEnabled();

Source Link

Usage

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

License:Apache License

public PgPoolImpl(Vertx vertx, boolean closeVertx, PgPoolOptions options) {
    int maxSize = options.getMaxSize();
    if (maxSize < 1) {
        throw new IllegalArgumentException("Pool max size must be > 0");
    }/*from w w w  .j av a  2 s  .c  om*/
    if (options.isUsingDomainSocket() && !vertx.isNativeTransportEnabled()) {
        throw new VertxException("Native transport is not available");
    }
    this.context = vertx.getOrCreateContext();
    this.factory = new PgConnectionFactory(context, Vertx.currentContext() != null, options);
    this.pool = new ConnectionPool(factory::create, maxSize, options.getMaxWaitQueueSize());
    this.closeVertx = closeVertx;
}

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  .ja va 2  s.co  m*/
 * 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);
            }
        });
    }
}