Repository navigation
Use the DefaultConnectionPool for the SQL connection pool #1820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+370
−168
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/AcquireRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
| * which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
| */ | ||
|
|
||
| package io.vertx.sqlclient.impl.pool; | ||
|
|
||
| import io.vertx.core.Promise; | ||
| import io.vertx.core.internal.ContextInternal; | ||
| import io.vertx.core.internal.pool.Lease; | ||
| import io.vertx.sqlclient.impl.pool.SqlConnectionPool.PooledConnection; | ||
|
|
||
| /** | ||
| * The acquisition request of a pooled connection: the borrowed connection is handed over to the requester, | ||
| * which gives it back to the pool when it closes it. | ||
| * | ||
| * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> | ||
| */ | ||
| class AcquireRequest extends PoolRequest { | ||
|
|
||
| private final Promise<PooledConnection> handler; | ||
|
|
||
| AcquireRequest(SqlConnectionPool pool, ContextInternal context, Promise<PooledConnection> handler) { | ||
| super(pool, context); | ||
| this.handler = handler; | ||
| } | ||
|
|
||
| @Override | ||
| void handleSuccess(Lease<PooledConnection> lease) { | ||
| if (pool.afterAcquire != null) { | ||
| pool.afterAcquire.apply(lease.get().conn).onComplete((v, err) -> { | ||
| if (err == null) { | ||
| handleConnection(lease); | ||
| } else { | ||
| lease.recycle(); | ||
| handler.tryFail(err); | ||
| } | ||
| }); | ||
| } else { | ||
| handleConnection(lease); | ||
| } | ||
| } | ||
|
|
||
| private void handleConnection(Lease<PooledConnection> lease) { | ||
| PooledConnection pooled = lease.get(); | ||
| pooled.timerMetric = pool.beginMetric(); | ||
| // The lease is recycled when the connection is given back to the pool, see PooledConnection#cleanup | ||
| pooled.lease = lease; | ||
| handler.succeed(pooled); | ||
| } | ||
|
|
||
| @Override | ||
| void handleFailure(Throwable failure) { | ||
| handler.tryFail(failure); | ||
| } | ||
| } |
73 changes: 73 additions & 0 deletions
73
vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/pool/ExecuteRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright (c) 2011-2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
| * which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
| */ | ||
|
|
||
| package io.vertx.sqlclient.impl.pool; | ||
|
|
||
| import io.vertx.core.Completable; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.internal.ContextInternal; | ||
| import io.vertx.core.internal.PromiseInternal; | ||
| import io.vertx.core.internal.pool.Lease; | ||
| import io.vertx.sqlclient.impl.pool.SqlConnectionPool.PooledConnection; | ||
| import io.vertx.sqlclient.spi.connection.Connection; | ||
| import io.vertx.sqlclient.spi.protocol.CommandBase; | ||
|
|
||
| /** | ||
| * The acquisition request of a pooled query: borrow a connection, schedule the command on it and give the | ||
| * connection back to the pool. | ||
| * | ||
| * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> | ||
| */ | ||
| class ExecuteRequest<R> extends PoolRequest { | ||
|
|
||
| private final CommandBase<R> cmd; | ||
| private final Completable<R> handler; | ||
|
|
||
| ExecuteRequest(SqlConnectionPool pool, ContextInternal context, CommandBase<R> cmd, Completable<R> handler) { | ||
| super(pool, context); | ||
| this.cmd = cmd; | ||
| this.handler = handler; | ||
| } | ||
|
|
||
| @Override | ||
| void handleSuccess(Lease<PooledConnection> lease) { | ||
| // The pool delivers the lease on the context of the connection: emit on the context of the requester, | ||
| // like the command outcome | ||
| context.emit(lease, this::processSuccess); | ||
| } | ||
|
|
||
| private void processSuccess(Lease<PooledConnection> lease) { | ||
| PooledConnection pooled = lease.get(); | ||
| pooled.timerMetric = pool.beginMetric(); | ||
| Future<R> future; | ||
| if (pool.afterAcquire != null) { | ||
| Connection conn = pooled.conn; | ||
| future = pool.afterAcquire.apply(conn) | ||
| .compose(v -> Future.<R>future(d -> pooled.schedule(cmd, d))) | ||
| .eventually(() -> pool.beforeRecycle.apply(conn)); | ||
| } else { | ||
| PromiseInternal<R> pp = context.promise(); | ||
| pooled.schedule(cmd, pp); | ||
| future = pp; | ||
| } | ||
| future.onComplete((res, err) -> { | ||
| pool.endMetric(pooled.timerMetric); | ||
| pooled.refresh(); | ||
| lease.recycle(); | ||
| handler.complete(res, err); | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| void handleFailure(Throwable failure) { | ||
| context.emit(failure, handler::fail); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.