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;
}
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();
});
}));
}));
}
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;
}
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;
}
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;
}
Aggregations