Search in sources :

Example 1 with ConnectionFactory

use of io.vertx.sqlclient.spi.ConnectionFactory in project vertx-sql-client by eclipse-vertx.

the class MySQLDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    MySQLConnectOptions baseConnectOptions = MySQLConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, 1, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MySQLConnectionImpl(io.vertx.mysqlclient.impl.MySQLConnectionImpl) Driver(io.vertx.sqlclient.spi.Driver) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MySQLConnectionFactory(io.vertx.mysqlclient.impl.MySQLConnectionFactory) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) MySQLPool(io.vertx.mysqlclient.MySQLPool) CloseFuture(io.vertx.core.impl.CloseFuture) MySQLConnectionUriParser(io.vertx.mysqlclient.impl.MySQLConnectionUriParser) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) MySQLConnectionFactory(io.vertx.mysqlclient.impl.MySQLConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MySQLPoolImpl(io.vertx.mysqlclient.impl.MySQLPoolImpl) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Example 2 with ConnectionFactory

use of io.vertx.sqlclient.spi.ConnectionFactory in project vertx-sql-client by eclipse-vertx.

the class PgPoolTest method testConnectionClosedInProvider.

private void testConnectionClosedInProvider(TestContext ctx, boolean immediately) {
    Async async = ctx.async(2);
    ProxyServer proxy = ProxyServer.create(vertx, options.getPort(), options.getHost());
    AtomicReference<ProxyServer.Connection> proxyConn = new AtomicReference<>();
    proxy.proxyHandler(conn -> {
        proxyConn.set(conn);
        conn.connect();
    });
    proxy.listen(8080, "localhost", ctx.asyncAssertSuccess(v1 -> {
        PgConnectOptions options = new PgConnectOptions(this.options).setPort(8080).setHost("localhost");
        ConnectionFactory factory = PgDriver.INSTANCE.createConnectionFactory(vertx, options);
        PgPool pool = createPool(options, new PoolOptions().setMaxSize(1));
        pool.connectionProvider(context -> {
            Future<SqlConnection> fut = factory.connect(context);
            if (immediately) {
                return fut.map(conn -> {
                    conn.close();
                    return conn;
                });
            } else {
                return fut.flatMap(conn -> conn.close().map(conn));
            }
        });
        pool.getConnection(ctx.asyncAssertFailure(conn -> {
            vertx.runOnContext(v -> {
                ctx.assertEquals(0, pool.size());
                async.complete();
            });
        }));
    }));
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) PgSocketConnection(io.vertx.pgclient.impl.PgSocketConnection) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PgDriver(io.vertx.pgclient.spi.PgDriver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collectors.mapping(java.util.stream.Collectors.mapping) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) RepeatRule(io.vertx.ext.unit.junit.RepeatRule) Collector(java.util.stream.Collector) io.vertx.sqlclient(io.vertx.sqlclient) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) Test(org.junit.Test) EventLoop(io.netty.channel.EventLoop) Repeat(io.vertx.ext.unit.junit.Repeat) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Rule(org.junit.Rule) Handler(io.vertx.core.Handler) Collections(java.util.Collections) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) Async(io.vertx.ext.unit.Async) PgSocketConnection(io.vertx.pgclient.impl.PgSocketConnection) Future(io.vertx.core.Future) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 3 with ConnectionFactory

use of io.vertx.sqlclient.spi.ConnectionFactory in project vertx-sql-client by eclipse-vertx.

the class DB2Driver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    DB2ConnectOptions baseConnectOptions = DB2ConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    boolean pipelinedPool = options instanceof Db2PoolOptions && ((Db2PoolOptions) options).isPipelined();
    int pipeliningLimit = pipelinedPool ? baseConnectOptions.getPipeliningLimit() : 1;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, pipeliningLimit, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) DB2Pool(io.vertx.db2client.DB2Pool) CloseFuture(io.vertx.core.impl.CloseFuture) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) io.vertx.db2client.impl(io.vertx.db2client.impl) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Example 4 with ConnectionFactory

use of io.vertx.sqlclient.spi.ConnectionFactory in project vertx-sql-client by eclipse-vertx.

the class MSSQLDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    MSSQLConnectOptions baseConnectOptions = MSSQLConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, 1, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) MSSQLConnectionUriParser(io.vertx.mssqlclient.impl.MSSQLConnectionUriParser) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) MSSQLConnectionFactory(io.vertx.mssqlclient.impl.MSSQLConnectionFactory) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) MSSQLConnectionImpl(io.vertx.mssqlclient.impl.MSSQLConnectionImpl) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) CloseFuture(io.vertx.core.impl.CloseFuture) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) MSSQLPool(io.vertx.mssqlclient.MSSQLPool) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) MSSQLConnectionFactory(io.vertx.mssqlclient.impl.MSSQLConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) MSSQLConnectOptions(io.vertx.mssqlclient.MSSQLConnectOptions) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) MSSQLPoolImpl(io.vertx.mssqlclient.impl.MSSQLPoolImpl)

Example 5 with ConnectionFactory

use of io.vertx.sqlclient.spi.ConnectionFactory in project vertx-sql-client by eclipse-vertx.

the class PgDriver method newPoolImpl.

private PoolImpl newPoolImpl(VertxInternal vertx, List<? extends SqlConnectOptions> databases, PoolOptions options, CloseFuture closeFuture) {
    PgConnectOptions baseConnectOptions = PgConnectOptions.wrap(databases.get(0));
    QueryTracer tracer = vertx.tracer() == null ? null : new QueryTracer(vertx.tracer(), baseConnectOptions);
    VertxMetrics vertxMetrics = vertx.metricsSPI();
    ClientMetrics metrics = vertxMetrics != null ? vertxMetrics.createClientMetrics(baseConnectOptions.getSocketAddress(), "sql", baseConnectOptions.getMetricsName()) : null;
    boolean pipelinedPool = options instanceof PgPoolOptions && ((PgPoolOptions) options).isPipelined();
    int pipeliningLimit = pipelinedPool ? baseConnectOptions.getPipeliningLimit() : 1;
    PoolImpl pool = new PoolImpl(vertx, this, tracer, metrics, pipeliningLimit, options, null, null, closeFuture);
    List<ConnectionFactory> lst = databases.stream().map(o -> createConnectionFactory(vertx, o)).collect(Collectors.toList());
    ConnectionFactory factory = ConnectionFactory.roundRobinSelector(lst);
    pool.connectionProvider(factory::connect);
    pool.init();
    closeFuture.add(factory);
    return pool;
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) VertxInternal(io.vertx.core.impl.VertxInternal) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) Vertx(io.vertx.core.Vertx) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) ContextInternal(io.vertx.core.impl.ContextInternal) PgPool(io.vertx.pgclient.PgPool) Driver(io.vertx.sqlclient.spi.Driver) PoolImpl(io.vertx.sqlclient.impl.PoolImpl) Collectors(java.util.stream.Collectors) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) PoolOptions(io.vertx.sqlclient.PoolOptions) Connection(io.vertx.sqlclient.impl.Connection) List(java.util.List) CloseFuture(io.vertx.core.impl.CloseFuture) JsonObject(io.vertx.core.json.JsonObject) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) SqlConnectionInternal(io.vertx.sqlclient.impl.SqlConnectionInternal) PgConnectOptions(io.vertx.pgclient.PgConnectOptions) io.vertx.pgclient.impl(io.vertx.pgclient.impl) PgConnectOptions(io.vertx.pgclient.PgConnectOptions) VertxMetrics(io.vertx.core.spi.metrics.VertxMetrics) ConnectionFactory(io.vertx.sqlclient.spi.ConnectionFactory) QueryTracer(io.vertx.sqlclient.impl.tracing.QueryTracer) ClientMetrics(io.vertx.core.spi.metrics.ClientMetrics) PoolImpl(io.vertx.sqlclient.impl.PoolImpl)

Aggregations

ConnectionFactory (io.vertx.sqlclient.spi.ConnectionFactory)8 PoolOptions (io.vertx.sqlclient.PoolOptions)7 Vertx (io.vertx.core.Vertx)6 ContextInternal (io.vertx.core.impl.ContextInternal)6 VertxInternal (io.vertx.core.impl.VertxInternal)6 SqlConnectionInternal (io.vertx.sqlclient.impl.SqlConnectionInternal)6 List (java.util.List)6 CloseFuture (io.vertx.core.impl.CloseFuture)5 JsonObject (io.vertx.core.json.JsonObject)5 ClientMetrics (io.vertx.core.spi.metrics.ClientMetrics)5 VertxMetrics (io.vertx.core.spi.metrics.VertxMetrics)5 SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)5 Connection (io.vertx.sqlclient.impl.Connection)5 PoolImpl (io.vertx.sqlclient.impl.PoolImpl)5 QueryTracer (io.vertx.sqlclient.impl.tracing.QueryTracer)5 Driver (io.vertx.sqlclient.spi.Driver)5 Collectors (java.util.stream.Collectors)5 Future (io.vertx.core.Future)4 TestContext (io.vertx.ext.unit.TestContext)3 Handler (io.vertx.core.Handler)2