You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by "Cole-Greer (via GitHub)" <gi...@apache.org> on 2025/11/03 17:57:32 UTC
Re: [PR] Added a new SessionedChildClient which reuses connection from parent … [tinkerpop]
Cole-Greer commented on code in PR #3258:
URL: https://github.com/apache/tinkerpop/pull/3258#discussion_r2487364506
##########
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java:
##########
@@ -773,6 +773,80 @@ public Client alias(final Map<String, String> aliases) {
}
}
+ /**
+ * A {@code Client} implementation that operates in the context of a session. {@code ChildSessionClient} is tied to
+ * another client as a child, it borrows the connection from the parent client's pool for the transaction. Requests are
+ * sent to a single server, where each request is bound to the same thread and same connection with the same set of
+ * bindings across requests.
+ * Transaction are not automatically committed. It is up the client to issue commit/rollback commands.
+ */
+ public final static class SessionedChildClient extends Client {
+ private final String sessionId;
+ private final boolean manageTransactions;
+ private final boolean maintainStateAfterException;
+ private final Client parentClient;
+ private Connection borrowedConnection;
+ private boolean closed;
+
+ public SessionedChildClient(final Client parentClient, String sessionId) {
+ super(parentClient.cluster, parentClient.settings);
+ this.parentClient = parentClient;
+ this.sessionId = sessionId;
+ this.closed = false;
+ this.manageTransactions = parentClient.settings.getSession().map(s -> s.manageTransactions).orElse(false);
+ this.maintainStateAfterException = parentClient.settings.getSession().map(s -> s.maintainStateAfterException).orElse(false);
+ }
+
+ public String getSessionId() {
+ return sessionId;
+ }
+
+ @Override
+ public RequestMessage.Builder buildMessage(final RequestMessage.Builder builder) {
+ builder.processor("session");
+ builder.addArg(Tokens.ARGS_SESSION, sessionId);
+ builder.addArg(Tokens.ARGS_MANAGE_TRANSACTION, manageTransactions);
+ builder.addArg(Tokens.ARGS_MAINTAIN_STATE_AFTER_EXCEPTION, maintainStateAfterException);
+ return builder;
+ }
+
+ @Override
+ protected void initializeImplementation() {
+ // do nothing, parentClient is already initialized
+ }
+
+ @Override
+ protected synchronized Connection chooseConnection(RequestMessage msg) throws TimeoutException, ConnectionException {
Review Comment:
Nit:
```suggestion
protected synchronized Connection chooseConnection(final RequestMessage msg) throws TimeoutException, ConnectionException {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tinkerpop.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org