Class HttpRemoteTransaction
- All Implemented Interfaces:
AutoCloseable,RemoteTransaction,RequestSubmitter,Transaction
Transaction implementation for HTTP-based remote connections.
This class provides synchronous, sequential request execution within a transaction context. All requests are pinned to a single host and include the transaction ID (after begin()).
Key characteristics:
- Synchronous API only - no submitAsync() methods
- Host pinning - all requests go to the same server
- Sequential execution - requests block until complete
Usage:
Transaction tx = cluster.transact("g");
GraphTraversalSource gtx = tx.begin();
gtx.addV("person").property("name", "alice").iterate();
tx.commit();
This class is NOT thread-safe.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
Transaction.CLOSE_BEHAVIOR, Transaction.Exceptions, Transaction.READ_WRITE_BEHAVIOR, Transaction.Status, Transaction.Symbols -
Field Summary
FieldsFields inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
NO_OP -
Constructor Summary
ConstructorsConstructorDescriptionHttpRemoteTransaction(Client.PinnedClient pinnedClient, String graphAlias) Creates a new HTTP transaction. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTransactionListener(Consumer<Transaction.Status> listener) Adds a listener that is called back with a status when a commit or rollback is successful.<T extends TraversalSource>
TStarts a transaction and returns a traversal source bound to it.voidRemoves all transaction listeners.voidclose()Closes the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.voidcommit()Commits the transaction.Returns the server-generated transaction ID, ornullif the transaction has not yet been started viabegin(Class).booleanisOpen()Determines if a transaction is currently open.onClose(Consumer<Transaction> consumer) Describes what happens to a transaction on a call toGraph.close().onReadWrite(Consumer<Transaction> consumer) Describes how a transaction is started when a read or a write occurs.voidAn internal function that signals a read or a write has occurred - not meant to be called directly by end users.voidremoveTransactionListener(Consumer<Transaction.Status> listener) Removes a transaction listener.voidrollback()Rolls back the transaction.Submits a Gremlin script and blocks until the response is received.Submits a Gremlin script with bound parameters and blocks until the response is received.submit(String gremlin, RequestOptions options) Submits a Gremlin script with request options and blocks until the response is received.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.tinkerpop.gremlin.structure.Transaction
begin, createThreadedTx
-
Field Details
-
closeConsumer
-
-
Constructor Details
-
HttpRemoteTransaction
Creates a new HTTP transaction.The transaction is not started until
begin(Class)is called. A host is selected at creation time and all requests will be pinned to it.- Parameters:
pinnedClient- the underlying client for connection accessgraphAlias- the graph/traversal source alias (e.g., "g")- Throws:
NoHostAvailableException- if no hosts are available in the cluster
-
-
Method Details
-
begin
Starts a transaction and returns a traversal source bound to it.When this transaction has not yet been started, this method sends
g.tx().begin()to the server, which returns the transaction ID that all subsequent requests will include. This method is idempotent: if the transaction is already open, it does not send a second begin to the server and does not throw - it reuses the existing transaction ID and returns a traversal source bound to the same transaction. A remote transaction is single-use, so once it has been closed (viacommit(),rollback(), timeout, or a failed begin) it cannot be reused and this method throws.- Specified by:
beginin interfaceTransaction- Type Parameters:
T- the type of the traversal source- Parameters:
traversalSourceClass- the class of the traversal source to create- Returns:
- a traversal source bound to this transaction
- Throws:
IllegalStateException- if the transaction has already been closedRuntimeException- if the transaction fails to begin
-
commit
public void commit()Commits the transaction.Sends
g.tx().commit()to the server and closes the transaction.- Specified by:
commitin interfaceTransaction- Throws:
IllegalStateException- if the transaction is not openTransactionException- if the commit fails
-
rollback
public void rollback()Rolls back the transaction.Sends
g.tx().rollback()to the server and closes the transaction.- Specified by:
rollbackin interfaceTransaction- Throws:
IllegalStateException- if the transaction is not openTransactionException- if the rollback fails
-
getTransactionId
Returns the server-generated transaction ID, ornullif the transaction has not yet been started viabegin(Class).- Specified by:
getTransactionIdin interfaceRemoteTransaction- Returns:
- the transaction ID, or null if not yet begun
-
isOpen
public boolean isOpen()Description copied from interface:TransactionDetermines if a transaction is currently open.- Specified by:
isOpenin interfaceTransaction
-
readWrite
public void readWrite()Description copied from interface:TransactionAn internal function that signals a read or a write has occurred - not meant to be called directly by end users.- Specified by:
readWritein interfaceTransaction
-
close
public void close()Description copied from interface:TransactionCloses the transaction where the default close behavior defined by {Transaction.onClose(Consumer)} will be executed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceTransaction
-
onReadWrite
Description copied from interface:TransactionDescribes how a transaction is started when a read or a write occurs. This value can be set using standard behaviors defined inTransaction.READ_WRITE_BEHAVIORor a mapperConsumerfunction.- Specified by:
onReadWritein interfaceTransaction
-
onClose
Description copied from interface:TransactionDescribes what happens to a transaction on a call toGraph.close(). This value can be set using standard behavior defined inTransaction.CLOSE_BEHAVIORor a mapperConsumerfunction.- Specified by:
onClosein interfaceTransaction
-
addTransactionListener
Description copied from interface:TransactionAdds a listener that is called back with a status when a commit or rollback is successful. It is expected that listeners be bound to the current thread as is standard for transactions. Therefore a listener registered in the current thread will not get callback events from a commit or rollback call in a different thread.- Specified by:
addTransactionListenerin interfaceTransaction
-
removeTransactionListener
Description copied from interface:TransactionRemoves a transaction listener.- Specified by:
removeTransactionListenerin interfaceTransaction
-
clearTransactionListeners
public void clearTransactionListeners()Description copied from interface:TransactionRemoves all transaction listeners.- Specified by:
clearTransactionListenersin interfaceTransaction
-
submit
Description copied from interface:RequestSubmitterSubmits a Gremlin script and blocks until the response is received.- Specified by:
submitin interfaceRequestSubmitter- Parameters:
gremlin- the Gremlin script to execute- Returns:
- the results of the script execution
-
submit
Description copied from interface:RequestSubmitterSubmits a Gremlin script with bound parameters and blocks until the response is received.Prefer this method over string concatenation when executing scripts with variable arguments, as parameterized scripts perform better.
- Specified by:
submitin interfaceRequestSubmitter- Parameters:
gremlin- the Gremlin script to executeparameters- a map of parameters that will be bound to the script on execution- Returns:
- the results of the script execution
-
submit
Description copied from interface:RequestSubmitterSubmits a Gremlin script with request options and blocks until the response is received.- Specified by:
submitin interfaceRequestSubmitter- Parameters:
gremlin- the Gremlin script to executeoptions- the options to supply for this request- Returns:
- the results of the script execution
-